1 /* $Id: ss_context.c,v 1.19 2002/10/24 23:57:25 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@valinux.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"
41 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
49 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
53 _swsetup_CreateContext( GLcontext
*ctx
)
55 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
56 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
61 swsetup
->verts
= (SWvertex
*) ALIGN_CALLOC( sizeof(SWvertex
) * tnl
->vb
.Size
,
63 if (!swsetup
->verts
) {
68 ctx
->swsetup_context
= swsetup
;
70 swsetup
->NewState
= ~0;
71 _swsetup_vb_init( ctx
);
72 _swsetup_trifuncs_init( ctx
);
78 _swsetup_DestroyContext( GLcontext
*ctx
)
80 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
84 ALIGN_FREE(swsetup
->verts
);
86 if (swsetup
->ChanSecondaryColor
.Ptr
)
87 ALIGN_FREE(swsetup
->ChanSecondaryColor
.Ptr
);
89 if (swsetup
->ChanColor
.Ptr
)
90 ALIGN_FREE(swsetup
->ChanColor
.Ptr
);
93 ctx
->swsetup_context
= 0;
98 _swsetup_RenderPrimitive( GLcontext
*ctx
, GLenum mode
)
100 SWSETUP_CONTEXT(ctx
)->render_prim
= mode
;
101 _swrast_render_primitive( ctx
, mode
);
105 * We patch this function into tnl->Driver.Render.Start.
106 * It's called when we start rendering a vertex buffer.
109 _swsetup_RenderStart( GLcontext
*ctx
)
111 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
112 GLuint new_state
= swsetup
->NewState
;
114 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
115 _swsetup_choose_trifuncs( ctx
);
118 if (new_state
& _SWSETUP_NEW_VERTS
) {
119 _swsetup_choose_rastersetup_func( ctx
);
122 swsetup
->NewState
= 0;
124 _swrast_render_start( ctx
);
128 * We patch this function into tnl->Driver.Render.Finish.
129 * It's called when we finish rendering a vertex buffer.
132 _swsetup_RenderFinish( GLcontext
*ctx
)
134 _swrast_render_finish( ctx
);
138 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
140 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
141 swsetup
->NewState
|= new_state
;
146 _swsetup_Wakeup( GLcontext
*ctx
)
148 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
149 tnl
->Driver
.Render
.Start
= _swsetup_RenderStart
;
150 tnl
->Driver
.Render
.Finish
= _swsetup_RenderFinish
;
151 tnl
->Driver
.Render
.PrimitiveNotify
= _swsetup_RenderPrimitive
;
154 tnl
->Driver
.Render
.ClippedPolygon
= _tnl_RenderClippedPolygon
; /* new */
155 tnl
->Driver
.Render
.ClippedLine
= _tnl_RenderClippedLine
; /* new */
160 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
161 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
162 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
164 tnl
->Driver
.Render
.Multipass
= 0;
165 _tnl_need_projected_coords( ctx
, GL_TRUE
);
166 _swsetup_InvalidateState( ctx
, ~0 );