2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 * Keith Whitwell <keith@tungstengraphics.com>
30 #include "bufferobj.h"
34 #include "prog_statevars.h"
38 #include "s_context.h"
42 #include "s_triangle.h"
43 #include "s_texfilter.h"
47 * Recompute the value of swrast->_RasterMask, etc. according to
48 * the current context. The _RasterMask field can be easily tested by
49 * drivers to determine certain basic GL state (does the primitive need
50 * stenciling, logic-op, fog, etc?).
53 _swrast_update_rasterflags( GLcontext
*ctx
)
55 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
56 GLbitfield rasterMask
= 0;
58 if (ctx
->Color
.AlphaEnabled
) rasterMask
|= ALPHATEST_BIT
;
59 if (ctx
->Color
.BlendEnabled
) rasterMask
|= BLEND_BIT
;
60 if (ctx
->Depth
.Test
) rasterMask
|= DEPTH_BIT
;
61 if (swrast
->_FogEnabled
) rasterMask
|= FOG_BIT
;
62 if (ctx
->Scissor
.Enabled
) rasterMask
|= CLIP_BIT
;
63 if (ctx
->Stencil
.Enabled
) rasterMask
|= STENCIL_BIT
;
64 if (ctx
->Visual
.rgbMode
) {
65 const GLuint colorMask
= *((GLuint
*) &ctx
->Color
.ColorMask
);
66 if (colorMask
!= 0xffffffff) rasterMask
|= MASKING_BIT
;
67 if (ctx
->Color
._LogicOpEnabled
) rasterMask
|= LOGIC_OP_BIT
;
68 if (ctx
->Texture
._EnabledUnits
) rasterMask
|= TEXTURE_BIT
;
71 if (ctx
->Color
.IndexMask
!= 0xffffffff) rasterMask
|= MASKING_BIT
;
72 if (ctx
->Color
.IndexLogicOpEnabled
) rasterMask
|= LOGIC_OP_BIT
;
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
;
82 if (ctx
->Query
.CurrentOcclusionObject
)
83 rasterMask
|= OCCLUSION_BIT
;
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.
90 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
[0] != 1) {
91 /* more than one color buffer designated for writing (or zero buffers) */
92 rasterMask
|= MULTI_DRAW_BIT
;
94 else if (ctx
->Visual
.rgbMode
&& *((GLuint
*) ctx
->Color
.ColorMask
) == 0) {
95 rasterMask
|= MULTI_DRAW_BIT
; /* all RGBA channels disabled */
97 else if (!ctx
->Visual
.rgbMode
&& ctx
->Color
.IndexMask
==0) {
98 rasterMask
|= MULTI_DRAW_BIT
; /* all color index bits disabled */
101 if (ctx
->FragmentProgram
._Current
) {
102 rasterMask
|= FRAGPROG_BIT
;
105 if (ctx
->Shader
._FragmentShaderPresent
) {
106 rasterMask
|= FRAGPROG_BIT
;
109 if (ctx
->ATIFragmentShader
._Enabled
) {
110 rasterMask
|= ATIFRAGSHADER_BIT
;
113 #if CHAN_TYPE == GL_FLOAT
114 if (ctx
->Color
.ClampFragmentColor
== GL_TRUE
) {
115 rasterMask
|= CLAMPING_BIT
;
119 SWRAST_CONTEXT(ctx
)->_RasterMask
= rasterMask
;
124 * Examine polycon culls tate to compute the _BackfaceSign field.
125 * _BackfaceSign will be 0 if no culling, -1 if culling back-faces,
126 * and 1 if culling front-faces. The Polygon FrontFace state also
130 _swrast_update_polygon( GLcontext
*ctx
)
132 GLfloat backface_sign
= 1;
134 if (ctx
->Polygon
.CullFlag
) {
136 switch(ctx
->Polygon
.CullFaceMode
) {
138 if(ctx
->Polygon
.FrontFace
==GL_CCW
)
142 if(ctx
->Polygon
.FrontFace
!=GL_CCW
)
146 case GL_FRONT_AND_BACK
:
155 SWRAST_CONTEXT(ctx
)->_BackfaceSign
= backface_sign
;
160 * Update the _PreferPixelFog field to indicate if we need to compute
161 * fog factors per-fragment.
164 _swrast_update_fog_hint( GLcontext
*ctx
)
166 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
167 swrast
->_PreferPixelFog
= (!swrast
->AllowVertexFog
||
168 ctx
->FragmentProgram
._Current
||
169 (ctx
->Hint
.Fog
== GL_NICEST
&&
170 swrast
->AllowPixelFog
));
176 * Update the swrast->_AnyTextureCombine flag.
179 _swrast_update_texture_env( GLcontext
*ctx
)
181 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
183 swrast
->_AnyTextureCombine
= GL_FALSE
;
184 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
185 if (ctx
->Texture
.Unit
[i
].EnvMode
== GL_COMBINE_EXT
||
186 ctx
->Texture
.Unit
[i
].EnvMode
== GL_COMBINE4_NV
) {
187 swrast
->_AnyTextureCombine
= GL_TRUE
;
195 * Update swrast->_FogColor and swrast->_FogEnable values.
198 _swrast_update_fog_state( GLcontext
*ctx
)
200 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
201 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
._Current
;
203 /* determine if fog is needed, and if so, which fog mode */
204 swrast
->_FogEnabled
= GL_FALSE
;
205 if (fp
&& fp
->Base
.Target
== GL_FRAGMENT_PROGRAM_ARB
) {
206 if (fp
->FogOption
!= GL_NONE
) {
207 swrast
->_FogEnabled
= GL_TRUE
;
208 swrast
->_FogMode
= fp
->FogOption
;
211 else if (ctx
->Fog
.Enabled
) {
212 swrast
->_FogEnabled
= GL_TRUE
;
213 swrast
->_FogMode
= ctx
->Fog
.Mode
;
219 * Update state for running fragment programs. Basically, load the
220 * program parameters with current state values.
223 _swrast_update_fragment_program(GLcontext
*ctx
, GLbitfield newState
)
225 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
._Current
;
228 /* XXX Need a way to trigger the initial loading of parameters
229 * even when there's no recent state changes.
231 if (fp
->Base
.Parameters
->StateFlags
& newState
)
233 _mesa_load_state_parameters(ctx
, fp
->Base
.Parameters
);
239 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \
244 /* State referenced by _swrast_choose_triangle, _swrast_choose_line.
246 #define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \
253 _SWRAST_NEW_RASTERMASK| \
256 _DD_NEW_SEPARATE_SPECULAR)
258 #define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \
265 _DD_NEW_SEPARATE_SPECULAR)
267 #define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \
273 _DD_NEW_SEPARATE_SPECULAR)
275 #define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE
277 #define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE
279 #define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR
284 * Stub for swrast->Triangle to select a true triangle function
285 * after a state change.
288 _swrast_validate_triangle( GLcontext
*ctx
,
293 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
295 _swrast_validate_derived( ctx
);
296 swrast
->choose_triangle( ctx
);
297 ASSERT(swrast
->Triangle
);
299 if (ctx
->Texture
._EnabledUnits
== 0
300 && NEED_SECONDARY_COLOR(ctx
)
301 && !ctx
->FragmentProgram
._Current
) {
302 /* separate specular color, but no texture */
303 swrast
->SpecTriangle
= swrast
->Triangle
;
304 swrast
->Triangle
= _swrast_add_spec_terms_triangle
;
307 swrast
->Triangle( ctx
, v0
, v1
, v2
);
311 * Called via swrast->Line. Examine current GL state and choose a software
312 * line routine. Then call it.
315 _swrast_validate_line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
317 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
319 _swrast_validate_derived( ctx
);
320 swrast
->choose_line( ctx
);
321 ASSERT(swrast
->Line
);
323 if (ctx
->Texture
._EnabledUnits
== 0
324 && NEED_SECONDARY_COLOR(ctx
)
325 && !ctx
->FragmentProgram
._Current
) {
326 swrast
->SpecLine
= swrast
->Line
;
327 swrast
->Line
= _swrast_add_spec_terms_line
;
331 swrast
->Line( ctx
, v0
, v1
);
335 * Called via swrast->Point. Examine current GL state and choose a software
336 * point routine. Then call it.
339 _swrast_validate_point( GLcontext
*ctx
, const SWvertex
*v0
)
341 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
343 _swrast_validate_derived( ctx
);
344 swrast
->choose_point( ctx
);
346 if (ctx
->Texture
._EnabledUnits
== 0
347 && NEED_SECONDARY_COLOR(ctx
)
348 && !ctx
->FragmentProgram
._Current
) {
349 swrast
->SpecPoint
= swrast
->Point
;
350 swrast
->Point
= _swrast_add_spec_terms_point
;
353 swrast
->Point( ctx
, v0
);
358 * Called via swrast->BlendFunc. Examine GL state to choose a blending
359 * function, then call it.
362 _swrast_validate_blend_func(GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
363 GLvoid
*src
, const GLvoid
*dst
,
366 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
368 _swrast_validate_derived( ctx
); /* why is this needed? */
369 _swrast_choose_blend_func( ctx
, chanType
);
371 swrast
->BlendFunc( ctx
, n
, mask
, src
, dst
, chanType
);
376 * Make sure we have texture image data for all the textures we may need
377 * for subsequent rendering.
380 _swrast_validate_texture_images(GLcontext
*ctx
)
382 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
385 if (!swrast
->ValidateTextureImage
|| !ctx
->Texture
._EnabledUnits
) {
386 /* no textures enabled, or no way to validate images! */
390 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
391 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
392 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[u
]._Current
;
395 GLuint numFaces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
397 for (face
= 0; face
< numFaces
; face
++) {
399 for (lvl
= texObj
->BaseLevel
; lvl
<= texObj
->_MaxLevel
; lvl
++) {
400 struct gl_texture_image
*texImg
= texObj
->Image
[face
][lvl
];
401 if (texImg
&& !texImg
->Data
) {
402 swrast
->ValidateTextureImage(ctx
, texObj
, face
, lvl
);
403 ASSERT(texObj
->Image
[face
][lvl
]->Data
);
414 * Free the texture image data attached to all currently enabled
415 * textures. Meant to be called by device drivers when transitioning
416 * from software to hardware rendering.
419 _swrast_eject_texture_images(GLcontext
*ctx
)
423 if (!ctx
->Texture
._EnabledUnits
) {
424 /* no textures enabled */
428 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
429 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
430 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[u
]._Current
;
433 GLuint numFaces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
435 for (face
= 0; face
< numFaces
; face
++) {
437 for (lvl
= texObj
->BaseLevel
; lvl
<= texObj
->_MaxLevel
; lvl
++) {
438 struct gl_texture_image
*texImg
= texObj
->Image
[face
][lvl
];
439 if (texImg
&& texImg
->Data
) {
440 _mesa_free_texmemory(texImg
->Data
);
453 _swrast_sleep( GLcontext
*ctx
, GLbitfield new_state
)
455 (void) ctx
; (void) new_state
;
460 _swrast_invalidate_state( GLcontext
*ctx
, GLbitfield new_state
)
462 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
465 swrast
->NewState
|= new_state
;
467 /* After 10 statechanges without any swrast functions being called,
468 * put the module to sleep.
470 if (++swrast
->StateChanges
> 10) {
471 swrast
->InvalidateState
= _swrast_sleep
;
472 swrast
->NewState
= ~0;
476 if (new_state
& swrast
->InvalidateTriangleMask
)
477 swrast
->Triangle
= _swrast_validate_triangle
;
479 if (new_state
& swrast
->InvalidateLineMask
)
480 swrast
->Line
= _swrast_validate_line
;
482 if (new_state
& swrast
->InvalidatePointMask
)
483 swrast
->Point
= _swrast_validate_point
;
485 if (new_state
& _SWRAST_NEW_BLEND_FUNC
)
486 swrast
->BlendFunc
= _swrast_validate_blend_func
;
488 if (new_state
& _SWRAST_NEW_TEXTURE_SAMPLE_FUNC
)
489 for (i
= 0 ; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
490 swrast
->TextureSample
[i
] = NULL
;
495 _swrast_update_texture_samplers(GLcontext
*ctx
)
497 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
500 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
501 const struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[u
]._Current
;
502 /* Note: If tObj is NULL, the sample function will be a simple
503 * function that just returns opaque black (0,0,0,1).
505 swrast
->TextureSample
[u
] = _swrast_choose_texture_sample_func(ctx
, tObj
);
511 _swrast_validate_derived( GLcontext
*ctx
)
513 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
515 if (swrast
->NewState
) {
516 if (swrast
->NewState
& _NEW_POLYGON
)
517 _swrast_update_polygon( ctx
);
519 if (swrast
->NewState
& (_NEW_HINT
| _NEW_PROGRAM
))
520 _swrast_update_fog_hint( ctx
);
522 if (swrast
->NewState
& _SWRAST_NEW_TEXTURE_ENV_MODE
)
523 _swrast_update_texture_env( ctx
);
525 if (swrast
->NewState
& (_NEW_FOG
| _NEW_PROGRAM
))
526 _swrast_update_fog_state( ctx
);
528 if (swrast
->NewState
& (_NEW_MODELVIEW
|
530 _NEW_TEXTURE_MATRIX
|
539 _swrast_update_fragment_program( ctx
, swrast
->NewState
);
541 if (swrast
->NewState
& _NEW_TEXTURE
)
542 _swrast_update_texture_samplers( ctx
);
544 if (swrast
->NewState
& (_NEW_TEXTURE
| _NEW_PROGRAM
))
545 _swrast_validate_texture_images( ctx
);
547 if (swrast
->NewState
& _SWRAST_NEW_RASTERMASK
)
548 _swrast_update_rasterflags( ctx
);
550 swrast
->NewState
= 0;
551 swrast
->StateChanges
= 0;
552 swrast
->InvalidateState
= _swrast_invalidate_state
;
556 #define SWRAST_DEBUG 0
558 /* Public entrypoints: See also s_accum.c, s_bitmap.c, etc.
561 _swrast_Quad( GLcontext
*ctx
,
562 const SWvertex
*v0
, const SWvertex
*v1
,
563 const SWvertex
*v2
, const SWvertex
*v3
)
566 _mesa_debug(ctx
, "_swrast_Quad\n");
567 _swrast_print_vertex( ctx
, v0
);
568 _swrast_print_vertex( ctx
, v1
);
569 _swrast_print_vertex( ctx
, v2
);
570 _swrast_print_vertex( ctx
, v3
);
572 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v3
);
573 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v1
, v2
, v3
);
577 _swrast_Triangle( GLcontext
*ctx
, const SWvertex
*v0
,
578 const SWvertex
*v1
, const SWvertex
*v2
)
581 _mesa_debug(ctx
, "_swrast_Triangle\n");
582 _swrast_print_vertex( ctx
, v0
);
583 _swrast_print_vertex( ctx
, v1
);
584 _swrast_print_vertex( ctx
, v2
);
586 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
);
590 _swrast_Line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
593 _mesa_debug(ctx
, "_swrast_Line\n");
594 _swrast_print_vertex( ctx
, v0
);
595 _swrast_print_vertex( ctx
, v1
);
597 SWRAST_CONTEXT(ctx
)->Line( ctx
, v0
, v1
);
601 _swrast_Point( GLcontext
*ctx
, const SWvertex
*v0
)
604 _mesa_debug(ctx
, "_swrast_Point\n");
605 _swrast_print_vertex( ctx
, v0
);
607 SWRAST_CONTEXT(ctx
)->Point( ctx
, v0
);
611 _swrast_InvalidateState( GLcontext
*ctx
, GLbitfield new_state
)
614 _mesa_debug(ctx
, "_swrast_InvalidateState\n");
616 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, new_state
);
620 _swrast_ResetLineStipple( GLcontext
*ctx
)
623 _mesa_debug(ctx
, "_swrast_ResetLineStipple\n");
625 SWRAST_CONTEXT(ctx
)->StippleCounter
= 0;
629 _swrast_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
)
632 _mesa_debug(ctx
, "_swrast_allow_vertex_fog %d\n", value
);
634 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, _NEW_HINT
);
635 SWRAST_CONTEXT(ctx
)->AllowVertexFog
= value
;
639 _swrast_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
)
642 _mesa_debug(ctx
, "_swrast_allow_pixel_fog %d\n", value
);
644 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, _NEW_HINT
);
645 SWRAST_CONTEXT(ctx
)->AllowPixelFog
= value
;
650 _swrast_CreateContext( GLcontext
*ctx
)
653 SWcontext
*swrast
= (SWcontext
*)CALLOC(sizeof(SWcontext
));
656 _mesa_debug(ctx
, "_swrast_CreateContext\n");
662 swrast
->NewState
= ~0;
664 swrast
->choose_point
= _swrast_choose_point
;
665 swrast
->choose_line
= _swrast_choose_line
;
666 swrast
->choose_triangle
= _swrast_choose_triangle
;
668 swrast
->InvalidatePointMask
= _SWRAST_NEW_POINT
;
669 swrast
->InvalidateLineMask
= _SWRAST_NEW_LINE
;
670 swrast
->InvalidateTriangleMask
= _SWRAST_NEW_TRIANGLE
;
672 swrast
->Point
= _swrast_validate_point
;
673 swrast
->Line
= _swrast_validate_line
;
674 swrast
->Triangle
= _swrast_validate_triangle
;
675 swrast
->InvalidateState
= _swrast_sleep
;
676 swrast
->BlendFunc
= _swrast_validate_blend_func
;
678 swrast
->AllowVertexFog
= GL_TRUE
;
679 swrast
->AllowPixelFog
= GL_TRUE
;
681 /* Optimized Accum buffer */
682 swrast
->_IntegerAccumMode
= GL_FALSE
;
683 swrast
->_IntegerAccumScaler
= 0.0;
685 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
686 swrast
->TextureSample
[i
] = NULL
;
688 swrast
->SpanArrays
= MALLOC_STRUCT(sw_span_arrays
);
689 if (!swrast
->SpanArrays
) {
693 swrast
->SpanArrays
->ChanType
= CHAN_TYPE
;
694 #if CHAN_TYPE == GL_UNSIGNED_BYTE
695 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->color
.sz1
.rgba
;
696 swrast
->SpanArrays
->spec
= swrast
->SpanArrays
->color
.sz1
.spec
;
697 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
698 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->color
.sz2
.rgba
;
699 swrast
->SpanArrays
->spec
= swrast
->SpanArrays
->color
.sz2
.spec
;
701 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->color
.sz4
.rgba
;
702 swrast
->SpanArrays
->spec
= swrast
->SpanArrays
->color
.sz4
.spec
;
705 /* init point span buffer */
706 swrast
->PointSpan
.primitive
= GL_POINT
;
707 swrast
->PointSpan
.end
= 0;
708 swrast
->PointSpan
.facing
= 0;
709 swrast
->PointSpan
.array
= swrast
->SpanArrays
;
711 swrast
->TexelBuffer
= (GLchan
*) MALLOC(ctx
->Const
.MaxTextureImageUnits
*
712 MAX_WIDTH
* 4 * sizeof(GLchan
));
713 if (!swrast
->TexelBuffer
) {
714 FREE(swrast
->SpanArrays
);
719 ctx
->swrast_context
= swrast
;
725 _swrast_DestroyContext( GLcontext
*ctx
)
727 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
730 _mesa_debug(ctx
, "_swrast_DestroyContext\n");
733 FREE( swrast
->SpanArrays
);
734 FREE( swrast
->TexelBuffer
);
737 ctx
->swrast_context
= 0;
741 struct swrast_device_driver
*
742 _swrast_GetDeviceDriverReference( GLcontext
*ctx
)
744 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
745 return &swrast
->Driver
;
749 _swrast_flush( GLcontext
*ctx
)
751 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
752 /* flush any pending fragments from rendering points */
753 if (swrast
->PointSpan
.end
> 0) {
754 if (ctx
->Visual
.rgbMode
) {
755 _swrast_write_rgba_span(ctx
, &(swrast
->PointSpan
));
758 _swrast_write_index_span(ctx
, &(swrast
->PointSpan
));
760 swrast
->PointSpan
.end
= 0;
765 _swrast_render_primitive( GLcontext
*ctx
, GLenum prim
)
767 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
768 if (swrast
->Primitive
== GL_POINTS
&& prim
!= GL_POINTS
) {
771 swrast
->Primitive
= prim
;
776 _swrast_render_start( GLcontext
*ctx
)
778 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
779 if (swrast
->Driver
.SpanRenderStart
)
780 swrast
->Driver
.SpanRenderStart( ctx
);
781 swrast
->PointSpan
.end
= 0;
785 _swrast_render_finish( GLcontext
*ctx
)
787 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
788 if (swrast
->Driver
.SpanRenderFinish
)
789 swrast
->Driver
.SpanRenderFinish( ctx
);
795 #define SWRAST_DEBUG_VERTICES 0
798 _swrast_print_vertex( GLcontext
*ctx
, const SWvertex
*v
)
802 if (SWRAST_DEBUG_VERTICES
) {
803 _mesa_debug(ctx
, "win %f %f %f %f\n",
804 v
->win
[0], v
->win
[1], v
->win
[2], v
->win
[3]);
806 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
807 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
808 _mesa_debug(ctx
, "texcoord[%d] %f %f %f %f\n", i
,
809 v
->texcoord
[i
][0], v
->texcoord
[i
][1],
810 v
->texcoord
[i
][2], v
->texcoord
[i
][3]);
812 #if CHAN_TYPE == GL_FLOAT
813 _mesa_debug(ctx
, "color %f %f %f %f\n",
814 v
->color
[0], v
->color
[1], v
->color
[2], v
->color
[3]);
815 _mesa_debug(ctx
, "spec %f %f %f %f\n",
816 v
->specular
[0], v
->specular
[1],
817 v
->specular
[2], v
->specular
[3]);
819 _mesa_debug(ctx
, "color %d %d %d %d\n",
820 v
->color
[0], v
->color
[1], v
->color
[2], v
->color
[3]);
821 _mesa_debug(ctx
, "spec %d %d %d %d\n",
822 v
->specular
[0], v
->specular
[1],
823 v
->specular
[2], v
->specular
[3]);
825 _mesa_debug(ctx
, "fog %f\n", v
->fog
);
826 _mesa_debug(ctx
, "index %d\n", v
->index
);
827 _mesa_debug(ctx
, "pointsize %f\n", v
->pointSize
);
828 _mesa_debug(ctx
, "\n");