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>
31 #include "ss_context.h"
32 #include "ss_triangle.h"
34 #include "swrast_setup.h"
36 #include "tnl/t_context.h"
37 #include "tnl/t_pipeline.h"
40 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
48 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
52 _swsetup_CreateContext( GLcontext
*ctx
)
54 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
55 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
60 swsetup
->verts
= (SWvertex
*) ALIGN_CALLOC( sizeof(SWvertex
) * tnl
->vb
.Size
,
62 if (!swsetup
->verts
) {
67 ctx
->swsetup_context
= swsetup
;
69 swsetup
->NewState
= ~0;
70 _swsetup_vb_init( ctx
);
71 _swsetup_trifuncs_init( ctx
);
77 _swsetup_DestroyContext( GLcontext
*ctx
)
79 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
83 ALIGN_FREE(swsetup
->verts
);
85 if (swsetup
->ChanSecondaryColor
.Ptr
)
86 ALIGN_FREE((void *) swsetup
->ChanSecondaryColor
.Ptr
);
88 if (swsetup
->ChanColor
.Ptr
)
89 ALIGN_FREE((void *) swsetup
->ChanColor
.Ptr
);
92 ctx
->swsetup_context
= 0;
97 _swsetup_RenderPrimitive( GLcontext
*ctx
, GLenum mode
)
99 SWSETUP_CONTEXT(ctx
)->render_prim
= mode
;
100 _swrast_render_primitive( ctx
, mode
);
104 * We patch this function into tnl->Driver.Render.Start.
105 * It's called when we start rendering a vertex buffer.
108 _swsetup_RenderStart( GLcontext
*ctx
)
110 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
111 GLuint new_state
= swsetup
->NewState
;
113 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
114 _swsetup_choose_trifuncs( ctx
);
117 if (new_state
& _SWSETUP_NEW_VERTS
) {
118 _swsetup_choose_rastersetup_func( ctx
);
121 swsetup
->NewState
= 0;
123 _swrast_render_start( ctx
);
127 * We patch this function into tnl->Driver.Render.Finish.
128 * It's called when we finish rendering a vertex buffer.
131 _swsetup_RenderFinish( GLcontext
*ctx
)
133 _swrast_render_finish( ctx
);
137 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
139 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
140 swsetup
->NewState
|= new_state
;
145 _swsetup_Wakeup( GLcontext
*ctx
)
147 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
148 tnl
->Driver
.Render
.Start
= _swsetup_RenderStart
;
149 tnl
->Driver
.Render
.Finish
= _swsetup_RenderFinish
;
150 tnl
->Driver
.Render
.PrimitiveNotify
= _swsetup_RenderPrimitive
;
153 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
; /* new */
154 tnl
->Driver
.Render
.ClippedLine
= _tnl_RenderClippedLine
; /* new */
159 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
160 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
161 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
163 tnl
->Driver
.Render
.Multipass
= 0;
164 _tnl_need_projected_coords( ctx
, GL_TRUE
);
165 _swsetup_InvalidateState( ctx
, ~0 );