2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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>
29 #include "main/imports.h"
30 #include "main/bufferobj.h"
31 #include "main/context.h"
32 #include "main/colormac.h"
33 #include "main/mtypes.h"
34 #include "main/teximage.h"
35 #include "shader/prog_parameter.h"
36 #include "shader/prog_statevars.h"
39 #include "s_context.h"
43 #include "s_triangle.h"
44 #include "s_texfilter.h"
48 * Recompute the value of swrast->_RasterMask, etc. according to
49 * the current context. The _RasterMask field can be easily tested by
50 * drivers to determine certain basic GL state (does the primitive need
51 * stenciling, logic-op, fog, etc?).
54 _swrast_update_rasterflags( GLcontext
*ctx
)
56 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
57 GLbitfield rasterMask
= 0;
59 if (ctx
->Color
.AlphaEnabled
) rasterMask
|= ALPHATEST_BIT
;
60 if (ctx
->Color
.BlendEnabled
) rasterMask
|= BLEND_BIT
;
61 if (ctx
->Depth
.Test
) rasterMask
|= DEPTH_BIT
;
62 if (swrast
->_FogEnabled
) rasterMask
|= FOG_BIT
;
63 if (ctx
->Scissor
.Enabled
) rasterMask
|= CLIP_BIT
;
64 if (ctx
->Stencil
._Enabled
) rasterMask
|= STENCIL_BIT
;
65 if (ctx
->Visual
.rgbMode
) {
66 const GLuint colorMask
= *((GLuint
*) &ctx
->Color
.ColorMask
);
67 if (colorMask
!= 0xffffffff) rasterMask
|= MASKING_BIT
;
68 if (ctx
->Color
._LogicOpEnabled
) rasterMask
|= LOGIC_OP_BIT
;
69 if (ctx
->Texture
._EnabledUnits
) rasterMask
|= TEXTURE_BIT
;
72 if (ctx
->Color
.IndexMask
!= 0xffffffff) rasterMask
|= MASKING_BIT
;
73 if (ctx
->Color
.IndexLogicOpEnabled
) rasterMask
|= LOGIC_OP_BIT
;
76 if ( ctx
->Viewport
.X
< 0
77 || ctx
->Viewport
.X
+ ctx
->Viewport
.Width
> (GLint
) ctx
->DrawBuffer
->Width
78 || ctx
->Viewport
.Y
< 0
79 || ctx
->Viewport
.Y
+ ctx
->Viewport
.Height
> (GLint
) ctx
->DrawBuffer
->Height
) {
80 rasterMask
|= CLIP_BIT
;
83 if (ctx
->Query
.CurrentOcclusionObject
)
84 rasterMask
|= OCCLUSION_BIT
;
87 /* If we're not drawing to exactly one color buffer set the
88 * MULTI_DRAW_BIT flag. Also set it if we're drawing to no
89 * buffers or the RGBA or CI mask disables all writes.
91 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
!= 1) {
92 /* more than one color buffer designated for writing (or zero buffers) */
93 rasterMask
|= MULTI_DRAW_BIT
;
95 else if (ctx
->Visual
.rgbMode
&& *((GLuint
*) ctx
->Color
.ColorMask
) == 0) {
96 rasterMask
|= MULTI_DRAW_BIT
; /* all RGBA channels disabled */
98 else if (!ctx
->Visual
.rgbMode
&& ctx
->Color
.IndexMask
==0) {
99 rasterMask
|= MULTI_DRAW_BIT
; /* all color index bits disabled */
102 if (ctx
->FragmentProgram
._Current
) {
103 rasterMask
|= FRAGPROG_BIT
;
106 if (ctx
->ATIFragmentShader
._Enabled
) {
107 rasterMask
|= ATIFRAGSHADER_BIT
;
110 #if CHAN_TYPE == GL_FLOAT
111 if (ctx
->Color
.ClampFragmentColor
== GL_TRUE
) {
112 rasterMask
|= CLAMPING_BIT
;
116 SWRAST_CONTEXT(ctx
)->_RasterMask
= rasterMask
;
121 * Examine polygon cull state to compute the _BackfaceCullSign field.
122 * _BackfaceCullSign will be 0 if no culling, -1 if culling back-faces,
123 * and 1 if culling front-faces. The Polygon FrontFace state also
127 _swrast_update_polygon( GLcontext
*ctx
)
129 GLfloat backface_sign
;
131 if (ctx
->Polygon
.CullFlag
) {
132 switch (ctx
->Polygon
.CullFaceMode
) {
134 backface_sign
= -1.0;
139 case GL_FRONT_AND_BACK
:
149 SWRAST_CONTEXT(ctx
)->_BackfaceCullSign
= backface_sign
;
151 /* This is for front/back-face determination, but not for culling */
152 SWRAST_CONTEXT(ctx
)->_BackfaceSign
153 = (ctx
->Polygon
.FrontFace
== GL_CW
) ? -1.0 : 1.0;
159 * Update the _PreferPixelFog field to indicate if we need to compute
160 * fog blend factors (from the fog coords) per-fragment.
163 _swrast_update_fog_hint( GLcontext
*ctx
)
165 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
166 swrast
->_PreferPixelFog
= (!swrast
->AllowVertexFog
||
167 ctx
->FragmentProgram
._Current
||
168 (ctx
->Hint
.Fog
== GL_NICEST
&&
169 swrast
->AllowPixelFog
));
175 * Update the swrast->_TextureCombinePrimary flag.
178 _swrast_update_texture_env( GLcontext
*ctx
)
180 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
183 swrast
->_TextureCombinePrimary
= GL_FALSE
;
185 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
186 const struct gl_tex_env_combine_state
*combine
=
187 ctx
->Texture
.Unit
[i
]._CurrentCombine
;
189 for (term
= 0; term
< combine
->_NumArgsRGB
; term
++) {
190 if (combine
->SourceRGB
[term
] == GL_PRIMARY_COLOR
) {
191 swrast
->_TextureCombinePrimary
= GL_TRUE
;
194 if (combine
->SourceA
[term
] == GL_PRIMARY_COLOR
) {
195 swrast
->_TextureCombinePrimary
= GL_TRUE
;
204 * Determine if we can defer texturing/shading until after Z/stencil
205 * testing. This potentially allows us to skip texturing/shading for
209 _swrast_update_deferred_texture(GLcontext
*ctx
)
211 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
212 if (ctx
->Color
.AlphaEnabled
) {
213 /* alpha test depends on post-texture/shader colors */
214 swrast
->_DeferredTexture
= GL_FALSE
;
217 const struct gl_fragment_program
*fprog
218 = ctx
->FragmentProgram
._Current
;
219 if (fprog
&& (fprog
->Base
.OutputsWritten
& (1 << FRAG_RESULT_DEPTH
))) {
220 /* Z comes from fragment program/shader */
221 swrast
->_DeferredTexture
= GL_FALSE
;
223 else if (ctx
->Query
.CurrentOcclusionObject
) {
224 /* occlusion query depends on shader discard/kill results */
225 swrast
->_DeferredTexture
= GL_FALSE
;
228 swrast
->_DeferredTexture
= GL_TRUE
;
235 * Update swrast->_FogColor and swrast->_FogEnable values.
238 _swrast_update_fog_state( GLcontext
*ctx
)
240 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
241 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
._Current
;
243 /* determine if fog is needed, and if so, which fog mode */
244 swrast
->_FogEnabled
= GL_FALSE
;
245 if (fp
&& fp
->Base
.Target
== GL_FRAGMENT_PROGRAM_ARB
) {
246 if (fp
->FogOption
!= GL_NONE
) {
247 swrast
->_FogEnabled
= GL_TRUE
;
248 swrast
->_FogMode
= fp
->FogOption
;
251 else if (ctx
->Fog
.Enabled
) {
252 swrast
->_FogEnabled
= GL_TRUE
;
253 swrast
->_FogMode
= ctx
->Fog
.Mode
;
259 * Update state for running fragment programs. Basically, load the
260 * program parameters with current state values.
263 _swrast_update_fragment_program(GLcontext
*ctx
, GLbitfield newState
)
265 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
._Current
;
267 _mesa_load_state_parameters(ctx
, fp
->Base
.Parameters
);
273 * See if we can do early diffuse+specular (primary+secondary) color
274 * add per vertex instead of per-fragment.
277 _swrast_update_specular_vertex_add(GLcontext
*ctx
)
279 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
280 GLboolean separateSpecular
= ctx
->Fog
.ColorSumEnabled
||
281 (ctx
->Light
.Enabled
&&
282 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
);
284 swrast
->SpecularVertexAdd
= (separateSpecular
285 && ctx
->Texture
._EnabledUnits
== 0x0
286 && !ctx
->FragmentProgram
._Current
287 && !ctx
->ATIFragmentShader
._Enabled
);
291 #define _SWRAST_NEW_DERIVED (_SWRAST_NEW_RASTERMASK | \
292 _NEW_PROGRAM_CONSTANTS | \
297 /* State referenced by _swrast_choose_triangle, _swrast_choose_line.
299 #define _SWRAST_NEW_TRIANGLE (_SWRAST_NEW_DERIVED | \
306 _SWRAST_NEW_RASTERMASK| \
309 _DD_NEW_SEPARATE_SPECULAR)
311 #define _SWRAST_NEW_LINE (_SWRAST_NEW_DERIVED | \
318 _DD_NEW_SEPARATE_SPECULAR)
320 #define _SWRAST_NEW_POINT (_SWRAST_NEW_DERIVED | \
326 _DD_NEW_SEPARATE_SPECULAR)
328 #define _SWRAST_NEW_TEXTURE_SAMPLE_FUNC _NEW_TEXTURE
330 #define _SWRAST_NEW_TEXTURE_ENV_MODE _NEW_TEXTURE
332 #define _SWRAST_NEW_BLEND_FUNC _NEW_COLOR
337 * Stub for swrast->Triangle to select a true triangle function
338 * after a state change.
341 _swrast_validate_triangle( GLcontext
*ctx
,
346 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
348 _swrast_validate_derived( ctx
);
349 swrast
->choose_triangle( ctx
);
350 ASSERT(swrast
->Triangle
);
352 if (swrast
->SpecularVertexAdd
) {
353 /* separate specular color, but no texture */
354 swrast
->SpecTriangle
= swrast
->Triangle
;
355 swrast
->Triangle
= _swrast_add_spec_terms_triangle
;
358 swrast
->Triangle( ctx
, v0
, v1
, v2
);
362 * Called via swrast->Line. Examine current GL state and choose a software
363 * line routine. Then call it.
366 _swrast_validate_line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
368 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
370 _swrast_validate_derived( ctx
);
371 swrast
->choose_line( ctx
);
372 ASSERT(swrast
->Line
);
374 if (swrast
->SpecularVertexAdd
) {
375 swrast
->SpecLine
= swrast
->Line
;
376 swrast
->Line
= _swrast_add_spec_terms_line
;
379 swrast
->Line( ctx
, v0
, v1
);
383 * Called via swrast->Point. Examine current GL state and choose a software
384 * point routine. Then call it.
387 _swrast_validate_point( GLcontext
*ctx
, const SWvertex
*v0
)
389 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
391 _swrast_validate_derived( ctx
);
392 swrast
->choose_point( ctx
);
394 if (swrast
->SpecularVertexAdd
) {
395 swrast
->SpecPoint
= swrast
->Point
;
396 swrast
->Point
= _swrast_add_spec_terms_point
;
399 swrast
->Point( ctx
, v0
);
404 * Called via swrast->BlendFunc. Examine GL state to choose a blending
405 * function, then call it.
408 _swrast_validate_blend_func(GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
409 GLvoid
*src
, const GLvoid
*dst
,
412 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
414 _swrast_validate_derived( ctx
); /* why is this needed? */
415 _swrast_choose_blend_func( ctx
, chanType
);
417 swrast
->BlendFunc( ctx
, n
, mask
, src
, dst
, chanType
);
422 * Make sure we have texture image data for all the textures we may need
423 * for subsequent rendering.
426 _swrast_validate_texture_images(GLcontext
*ctx
)
428 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
431 if (!swrast
->ValidateTextureImage
|| !ctx
->Texture
._EnabledUnits
) {
432 /* no textures enabled, or no way to validate images! */
436 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
437 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
438 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[u
]._Current
;
441 GLuint numFaces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
443 for (face
= 0; face
< numFaces
; face
++) {
445 for (lvl
= texObj
->BaseLevel
; lvl
<= texObj
->_MaxLevel
; lvl
++) {
446 struct gl_texture_image
*texImg
= texObj
->Image
[face
][lvl
];
447 if (texImg
&& !texImg
->Data
) {
448 swrast
->ValidateTextureImage(ctx
, texObj
, face
, lvl
);
449 ASSERT(texObj
->Image
[face
][lvl
]->Data
);
460 * Free the texture image data attached to all currently enabled
461 * textures. Meant to be called by device drivers when transitioning
462 * from software to hardware rendering.
465 _swrast_eject_texture_images(GLcontext
*ctx
)
469 if (!ctx
->Texture
._EnabledUnits
) {
470 /* no textures enabled */
474 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
475 if (ctx
->Texture
.Unit
[u
]._ReallyEnabled
) {
476 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[u
]._Current
;
479 GLuint numFaces
= (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) ? 6 : 1;
481 for (face
= 0; face
< numFaces
; face
++) {
483 for (lvl
= texObj
->BaseLevel
; lvl
<= texObj
->_MaxLevel
; lvl
++) {
484 struct gl_texture_image
*texImg
= texObj
->Image
[face
][lvl
];
485 if (texImg
&& texImg
->Data
) {
486 _mesa_free_texmemory(texImg
->Data
);
499 _swrast_sleep( GLcontext
*ctx
, GLbitfield new_state
)
501 (void) ctx
; (void) new_state
;
506 _swrast_invalidate_state( GLcontext
*ctx
, GLbitfield new_state
)
508 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
511 swrast
->NewState
|= new_state
;
513 /* After 10 statechanges without any swrast functions being called,
514 * put the module to sleep.
516 if (++swrast
->StateChanges
> 10) {
517 swrast
->InvalidateState
= _swrast_sleep
;
518 swrast
->NewState
= ~0;
522 if (new_state
& swrast
->InvalidateTriangleMask
)
523 swrast
->Triangle
= _swrast_validate_triangle
;
525 if (new_state
& swrast
->InvalidateLineMask
)
526 swrast
->Line
= _swrast_validate_line
;
528 if (new_state
& swrast
->InvalidatePointMask
)
529 swrast
->Point
= _swrast_validate_point
;
531 if (new_state
& _SWRAST_NEW_BLEND_FUNC
)
532 swrast
->BlendFunc
= _swrast_validate_blend_func
;
534 if (new_state
& _SWRAST_NEW_TEXTURE_SAMPLE_FUNC
)
535 for (i
= 0 ; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
536 swrast
->TextureSample
[i
] = NULL
;
541 _swrast_update_texture_samplers(GLcontext
*ctx
)
543 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
547 return; /* pipe hack */
549 for (u
= 0; u
< ctx
->Const
.MaxTextureImageUnits
; u
++) {
550 const struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[u
]._Current
;
551 /* Note: If tObj is NULL, the sample function will be a simple
552 * function that just returns opaque black (0,0,0,1).
554 swrast
->TextureSample
[u
] = _swrast_choose_texture_sample_func(ctx
, tObj
);
560 * Update swrast->_ActiveAttribs, swrast->_NumActiveAttribs,
561 * swrast->_ActiveAtttribMask.
564 _swrast_update_active_attribs(GLcontext
*ctx
)
566 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
570 * Compute _ActiveAttribsMask = which fragment attributes are needed.
572 if (ctx
->FragmentProgram
._Current
) {
573 /* fragment program/shader */
574 attribsMask
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
575 attribsMask
&= ~FRAG_BIT_WPOS
; /* WPOS is always handled specially */
577 else if (ctx
->ATIFragmentShader
._Enabled
) {
578 attribsMask
= ~0; /* XXX fix me */
584 #if CHAN_TYPE == GL_FLOAT
585 attribsMask
|= FRAG_BIT_COL0
;
588 if (ctx
->Fog
.ColorSumEnabled
||
589 (ctx
->Light
.Enabled
&&
590 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)) {
591 attribsMask
|= FRAG_BIT_COL1
;
594 if (swrast
->_FogEnabled
)
595 attribsMask
|= FRAG_BIT_FOGC
;
597 attribsMask
|= (ctx
->Texture
._EnabledUnits
<< FRAG_ATTRIB_TEX0
);
600 swrast
->_ActiveAttribMask
= attribsMask
;
602 /* Update _ActiveAttribs[] list */
605 for (i
= 0; i
< FRAG_ATTRIB_MAX
; i
++) {
606 if (attribsMask
& (1 << i
)) {
607 swrast
->_ActiveAttribs
[num
++] = i
;
608 /* how should this attribute be interpolated? */
609 if (i
== FRAG_ATTRIB_COL0
|| i
== FRAG_ATTRIB_COL1
)
610 swrast
->_InterpMode
[i
] = ctx
->Light
.ShadeModel
;
612 swrast
->_InterpMode
[i
] = GL_SMOOTH
;
615 swrast
->_NumActiveAttribs
= num
;
621 _swrast_validate_derived( GLcontext
*ctx
)
623 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
625 if (swrast
->NewState
) {
626 if (swrast
->NewState
& _NEW_POLYGON
)
627 _swrast_update_polygon( ctx
);
629 if (swrast
->NewState
& (_NEW_HINT
| _NEW_PROGRAM
))
630 _swrast_update_fog_hint( ctx
);
632 if (swrast
->NewState
& _SWRAST_NEW_TEXTURE_ENV_MODE
)
633 _swrast_update_texture_env( ctx
);
635 if (swrast
->NewState
& (_NEW_FOG
| _NEW_PROGRAM
))
636 _swrast_update_fog_state( ctx
);
638 if (swrast
->NewState
& (_NEW_PROGRAM_CONSTANTS
| _NEW_PROGRAM
))
639 _swrast_update_fragment_program( ctx
, swrast
->NewState
);
641 if (swrast
->NewState
& (_NEW_TEXTURE
| _NEW_PROGRAM
)) {
642 _swrast_update_texture_samplers( ctx
);
643 _swrast_validate_texture_images(ctx
);
646 if (swrast
->NewState
& (_NEW_COLOR
| _NEW_PROGRAM
))
647 _swrast_update_deferred_texture(ctx
);
649 if (swrast
->NewState
& _SWRAST_NEW_RASTERMASK
)
650 _swrast_update_rasterflags( ctx
);
652 if (swrast
->NewState
& (_NEW_DEPTH
|
657 _swrast_update_active_attribs(ctx
);
659 if (swrast
->NewState
& (_NEW_FOG
|
663 _swrast_update_specular_vertex_add(ctx
);
665 swrast
->NewState
= 0;
666 swrast
->StateChanges
= 0;
667 swrast
->InvalidateState
= _swrast_invalidate_state
;
671 #define SWRAST_DEBUG 0
673 /* Public entrypoints: See also s_accum.c, s_bitmap.c, etc.
676 _swrast_Quad( GLcontext
*ctx
,
677 const SWvertex
*v0
, const SWvertex
*v1
,
678 const SWvertex
*v2
, const SWvertex
*v3
)
681 _mesa_debug(ctx
, "_swrast_Quad\n");
682 _swrast_print_vertex( ctx
, v0
);
683 _swrast_print_vertex( ctx
, v1
);
684 _swrast_print_vertex( ctx
, v2
);
685 _swrast_print_vertex( ctx
, v3
);
687 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v3
);
688 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v1
, v2
, v3
);
692 _swrast_Triangle( GLcontext
*ctx
, const SWvertex
*v0
,
693 const SWvertex
*v1
, const SWvertex
*v2
)
696 _mesa_debug(ctx
, "_swrast_Triangle\n");
697 _swrast_print_vertex( ctx
, v0
);
698 _swrast_print_vertex( ctx
, v1
);
699 _swrast_print_vertex( ctx
, v2
);
701 SWRAST_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
);
705 _swrast_Line( GLcontext
*ctx
, const SWvertex
*v0
, const SWvertex
*v1
)
708 _mesa_debug(ctx
, "_swrast_Line\n");
709 _swrast_print_vertex( ctx
, v0
);
710 _swrast_print_vertex( ctx
, v1
);
712 SWRAST_CONTEXT(ctx
)->Line( ctx
, v0
, v1
);
716 _swrast_Point( GLcontext
*ctx
, const SWvertex
*v0
)
719 _mesa_debug(ctx
, "_swrast_Point\n");
720 _swrast_print_vertex( ctx
, v0
);
722 SWRAST_CONTEXT(ctx
)->Point( ctx
, v0
);
726 _swrast_InvalidateState( GLcontext
*ctx
, GLbitfield new_state
)
729 _mesa_debug(ctx
, "_swrast_InvalidateState\n");
731 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, new_state
);
735 _swrast_ResetLineStipple( GLcontext
*ctx
)
738 _mesa_debug(ctx
, "_swrast_ResetLineStipple\n");
740 SWRAST_CONTEXT(ctx
)->StippleCounter
= 0;
744 _swrast_SetFacing(GLcontext
*ctx
, GLuint facing
)
746 SWRAST_CONTEXT(ctx
)->PointLineFacing
= facing
;
750 _swrast_allow_vertex_fog( GLcontext
*ctx
, GLboolean value
)
753 _mesa_debug(ctx
, "_swrast_allow_vertex_fog %d\n", value
);
755 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, _NEW_HINT
);
756 SWRAST_CONTEXT(ctx
)->AllowVertexFog
= value
;
760 _swrast_allow_pixel_fog( GLcontext
*ctx
, GLboolean value
)
763 _mesa_debug(ctx
, "_swrast_allow_pixel_fog %d\n", value
);
765 SWRAST_CONTEXT(ctx
)->InvalidateState( ctx
, _NEW_HINT
);
766 SWRAST_CONTEXT(ctx
)->AllowPixelFog
= value
;
771 _swrast_CreateContext( GLcontext
*ctx
)
774 SWcontext
*swrast
= (SWcontext
*)CALLOC(sizeof(SWcontext
));
777 _mesa_debug(ctx
, "_swrast_CreateContext\n");
783 swrast
->NewState
= ~0;
785 swrast
->choose_point
= _swrast_choose_point
;
786 swrast
->choose_line
= _swrast_choose_line
;
787 swrast
->choose_triangle
= _swrast_choose_triangle
;
789 swrast
->InvalidatePointMask
= _SWRAST_NEW_POINT
;
790 swrast
->InvalidateLineMask
= _SWRAST_NEW_LINE
;
791 swrast
->InvalidateTriangleMask
= _SWRAST_NEW_TRIANGLE
;
793 swrast
->Point
= _swrast_validate_point
;
794 swrast
->Line
= _swrast_validate_line
;
795 swrast
->Triangle
= _swrast_validate_triangle
;
796 swrast
->InvalidateState
= _swrast_sleep
;
797 swrast
->BlendFunc
= _swrast_validate_blend_func
;
799 swrast
->AllowVertexFog
= GL_TRUE
;
800 swrast
->AllowPixelFog
= GL_TRUE
;
802 /* Optimized Accum buffer */
803 swrast
->_IntegerAccumMode
= GL_FALSE
;
804 swrast
->_IntegerAccumScaler
= 0.0;
806 for (i
= 0; i
< MAX_TEXTURE_IMAGE_UNITS
; i
++)
807 swrast
->TextureSample
[i
] = NULL
;
809 swrast
->SpanArrays
= MALLOC_STRUCT(sw_span_arrays
);
810 if (!swrast
->SpanArrays
) {
814 swrast
->SpanArrays
->ChanType
= CHAN_TYPE
;
815 #if CHAN_TYPE == GL_UNSIGNED_BYTE
816 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->rgba8
;
817 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
818 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->rgba16
;
820 swrast
->SpanArrays
->rgba
= swrast
->SpanArrays
->attribs
[FRAG_ATTRIB_COL0
];
823 /* init point span buffer */
824 swrast
->PointSpan
.primitive
= GL_POINT
;
825 swrast
->PointSpan
.end
= 0;
826 swrast
->PointSpan
.facing
= 0;
827 swrast
->PointSpan
.array
= swrast
->SpanArrays
;
829 swrast
->TexelBuffer
= (GLfloat
*) MALLOC(ctx
->Const
.MaxTextureImageUnits
*
830 MAX_WIDTH
* 4 * sizeof(GLfloat
));
831 if (!swrast
->TexelBuffer
) {
832 FREE(swrast
->SpanArrays
);
837 ctx
->swrast_context
= swrast
;
843 _swrast_DestroyContext( GLcontext
*ctx
)
845 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
848 _mesa_debug(ctx
, "_swrast_DestroyContext\n");
851 FREE( swrast
->SpanArrays
);
852 if (swrast
->ZoomedArrays
)
853 FREE( swrast
->ZoomedArrays
);
854 FREE( swrast
->TexelBuffer
);
857 ctx
->swrast_context
= 0;
861 struct swrast_device_driver
*
862 _swrast_GetDeviceDriverReference( GLcontext
*ctx
)
864 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
865 return &swrast
->Driver
;
869 _swrast_flush( GLcontext
*ctx
)
871 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
872 /* flush any pending fragments from rendering points */
873 if (swrast
->PointSpan
.end
> 0) {
874 if (ctx
->Visual
.rgbMode
) {
875 _swrast_write_rgba_span(ctx
, &(swrast
->PointSpan
));
878 _swrast_write_index_span(ctx
, &(swrast
->PointSpan
));
880 swrast
->PointSpan
.end
= 0;
885 _swrast_render_primitive( GLcontext
*ctx
, GLenum prim
)
887 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
888 if (swrast
->Primitive
== GL_POINTS
&& prim
!= GL_POINTS
) {
891 swrast
->Primitive
= prim
;
896 _swrast_render_start( GLcontext
*ctx
)
898 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
899 if (swrast
->Driver
.SpanRenderStart
)
900 swrast
->Driver
.SpanRenderStart( ctx
);
901 swrast
->PointSpan
.end
= 0;
905 _swrast_render_finish( GLcontext
*ctx
)
907 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
908 if (swrast
->Driver
.SpanRenderFinish
)
909 swrast
->Driver
.SpanRenderFinish( ctx
);
915 #define SWRAST_DEBUG_VERTICES 0
918 _swrast_print_vertex( GLcontext
*ctx
, const SWvertex
*v
)
922 if (SWRAST_DEBUG_VERTICES
) {
923 _mesa_debug(ctx
, "win %f %f %f %f\n",
924 v
->attrib
[FRAG_ATTRIB_WPOS
][0],
925 v
->attrib
[FRAG_ATTRIB_WPOS
][1],
926 v
->attrib
[FRAG_ATTRIB_WPOS
][2],
927 v
->attrib
[FRAG_ATTRIB_WPOS
][3]);
929 for (i
= 0 ; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
930 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
931 _mesa_debug(ctx
, "texcoord[%d] %f %f %f %f\n", i
,
932 v
->attrib
[FRAG_ATTRIB_TEX0
+ i
][0],
933 v
->attrib
[FRAG_ATTRIB_TEX0
+ i
][1],
934 v
->attrib
[FRAG_ATTRIB_TEX0
+ i
][2],
935 v
->attrib
[FRAG_ATTRIB_TEX0
+ i
][3]);
937 #if CHAN_TYPE == GL_FLOAT
938 _mesa_debug(ctx
, "color %f %f %f %f\n",
939 v
->color
[0], v
->color
[1], v
->color
[2], v
->color
[3]);
941 _mesa_debug(ctx
, "color %d %d %d %d\n",
942 v
->color
[0], v
->color
[1], v
->color
[2], v
->color
[3]);
944 _mesa_debug(ctx
, "spec %g %g %g %g\n",
945 v
->attrib
[FRAG_ATTRIB_COL1
][0],
946 v
->attrib
[FRAG_ATTRIB_COL1
][1],
947 v
->attrib
[FRAG_ATTRIB_COL1
][2],
948 v
->attrib
[FRAG_ATTRIB_COL1
][3]);
949 _mesa_debug(ctx
, "fog %f\n", v
->attrib
[FRAG_ATTRIB_FOGC
][0]);
950 _mesa_debug(ctx
, "index %d\n", v
->attrib
[FRAG_ATTRIB_CI
][0]);
951 _mesa_debug(ctx
, "pointsize %f\n", v
->pointSize
);
952 _mesa_debug(ctx
, "\n");