3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "ss_context.h"
33 #include "ss_triangle.h"
35 #include "swrast_setup.h"
37 #include "tnl/t_context.h"
38 #include "tnl/t_pipeline.h"
39 #include "tnl/t_vertex.h"
42 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
50 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
54 _swsetup_CreateContext( GLcontext
*ctx
)
56 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
57 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
62 swsetup
->verts
= (SWvertex
*) ALIGN_CALLOC( sizeof(SWvertex
) * tnl
->vb
.Size
,
64 if (!swsetup
->verts
) {
69 ctx
->swsetup_context
= swsetup
;
71 swsetup
->NewState
= ~0;
72 _swsetup_vb_init( ctx
);
73 _swsetup_trifuncs_init( ctx
);
79 _swsetup_DestroyContext( GLcontext
*ctx
)
81 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
85 ALIGN_FREE(swsetup
->verts
);
87 if (swsetup
->ChanSecondaryColor
.Ptr
)
88 ALIGN_FREE((void *) swsetup
->ChanSecondaryColor
.Ptr
);
90 if (swsetup
->ChanColor
.Ptr
)
91 ALIGN_FREE((void *) swsetup
->ChanColor
.Ptr
);
94 ctx
->swsetup_context
= 0;
99 _swsetup_RenderPrimitive( GLcontext
*ctx
, GLenum mode
)
101 SWSETUP_CONTEXT(ctx
)->render_prim
= mode
;
102 _swrast_render_primitive( ctx
, mode
);
106 * We patch this function into tnl->Driver.Render.Start.
107 * It's called when we start rendering a vertex buffer.
110 _swsetup_RenderStart( GLcontext
*ctx
)
112 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
113 GLuint new_state
= swsetup
->NewState
;
115 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
116 _swsetup_choose_trifuncs( ctx
);
119 if (new_state
& _SWSETUP_NEW_VERTS
) {
120 _swsetup_choose_rastersetup_func( ctx
);
123 swsetup
->NewState
= 0;
125 _swrast_render_start( ctx
);
129 * We patch this function into tnl->Driver.Render.Finish.
130 * It's called when we finish rendering a vertex buffer.
133 _swsetup_RenderFinish( GLcontext
*ctx
)
135 _swrast_render_finish( ctx
);
139 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
141 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
142 swsetup
->NewState
|= new_state
;
147 _swsetup_Wakeup( GLcontext
*ctx
)
149 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
150 tnl
->Driver
.Render
.Start
= _swsetup_RenderStart
;
151 tnl
->Driver
.Render
.Finish
= _swsetup_RenderFinish
;
152 tnl
->Driver
.Render
.PrimitiveNotify
= _swsetup_RenderPrimitive
;
155 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
; /* new */
156 tnl
->Driver
.Render
.ClippedLine
= _tnl_RenderClippedLine
; /* new */
161 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
162 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
163 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
165 tnl
->Driver
.Render
.Multipass
= 0;
166 _tnl_need_projected_coords( ctx
, GL_TRUE
);
167 _swsetup_InvalidateState( ctx
, ~0 );
174 /* Populate a swrast SWvertex from an attrib-style vertex.
177 _swsetup_Translate( GLcontext
*ctx
, const void *vertex
, SWvertex
*dest
)
182 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_POS
, dest
->win
);
184 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++)
185 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_TEX0
+i
, dest
->texcoord
[i
] );
187 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_COLOR0
, tmp
);
188 UNCLAMPED_FLOAT_TO_RGBA_CHAN( dest
->color
, tmp
);
190 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_COLOR1
, tmp
);
191 UNCLAMPED_FLOAT_TO_RGB_CHAN( dest
->specular
, tmp
);
193 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_FOG
, tmp
);
196 _tnl_get_attr( ctx
, vertex
, _TNL_ATTRIB_INDEX
, tmp
);
197 dest
->index
= (GLuint
) tmp
[0];
200 Need to check how pointsize is related to vertex program attributes:
202 _tnl_get_attr( ctx, vertex, _TNL_ATTRIB_POINTSIZE, tmp );
203 dest->pointSize = tmp[0];