1 /* $Id: ss_context.c,v 1.6 2001/01/05 02:26:49 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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>
35 #include "ss_context.h"
36 #include "ss_triangle.h"
39 #include "swrast_setup.h"
41 #include "tnl/t_context.h"
43 /* Stub for swsetup->Triangle to select a true triangle function
44 * after a state change.
47 _swsetup_validate_quad( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
48 GLuint v2
, GLuint v3
)
50 _swsetup_choose_trifuncs( ctx
);
51 SWSETUP_CONTEXT(ctx
)->Quad( ctx
, v0
, v1
, v2
, v3
);
55 _swsetup_validate_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
, GLuint v2
)
57 _swsetup_choose_trifuncs( ctx
);
58 SWSETUP_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
);
62 _swsetup_validate_line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
64 _swsetup_choose_trifuncs( ctx
);
65 SWSETUP_CONTEXT(ctx
)->Line( ctx
, v0
, v1
);
70 _swsetup_validate_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
72 _swsetup_choose_trifuncs( ctx
);
73 SWSETUP_CONTEXT(ctx
)->Points( ctx
, first
, last
);
79 _swsetup_validate_buildprojverts( GLcontext
*ctx
,
80 GLuint start
, GLuint end
, GLuint new_inputs
)
82 _swsetup_choose_rastersetup_func( ctx
);
83 SWSETUP_CONTEXT(ctx
)->BuildProjVerts( ctx
, start
, end
, new_inputs
);
87 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
93 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
97 /* TODO: sleep/wakeup mechanism
100 _swsetup_sleep( GLcontext
*ctx
, GLuint new_state
)
106 _swsetup_invalidate_state( GLcontext
*ctx
, GLuint new_state
)
108 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
110 swsetup
->NewState
|= new_state
;
112 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
113 swsetup
->Triangle
= _swsetup_validate_triangle
;
114 swsetup
->Line
= _swsetup_validate_line
;
115 swsetup
->Points
= _swsetup_validate_points
;
116 swsetup
->Quad
= _swsetup_validate_quad
;
119 if (new_state
& _SWSETUP_NEW_VERTS
) {
120 swsetup
->BuildProjVerts
= _swsetup_validate_buildprojverts
;
126 /* Dispatch from these fixed entrypoints to the state-dependent
130 _swsetup_Quad( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
131 GLuint v2
, GLuint v3
)
133 SWSETUP_CONTEXT(ctx
)->Quad( ctx
, v0
, v1
, v2
, v3
);
137 _swsetup_Triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
140 SWSETUP_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
);
144 _swsetup_Line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
146 SWSETUP_CONTEXT(ctx
)->Line( ctx
, v0
, v1
);
151 _swsetup_Points( GLcontext
*ctx
, GLuint first
, GLuint last
)
153 SWSETUP_CONTEXT(ctx
)->Points( ctx
, first
, last
);
157 _swsetup_BuildProjectedVertices( GLcontext
*ctx
, GLuint start
, GLuint end
,
160 SWSETUP_CONTEXT(ctx
)->BuildProjVerts( ctx
, start
, end
, new_inputs
);
164 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
166 SWSETUP_CONTEXT(ctx
)->InvalidateState( ctx
, new_state
);
171 _swsetup_CreateContext( GLcontext
*ctx
)
173 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
174 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
179 swsetup
->verts
= ALIGN_MALLOC( sizeof(SWvertex
) * tnl
->vb
.Size
, 32);
180 if (!swsetup
->verts
) {
185 ctx
->swsetup_context
= swsetup
;
187 swsetup
->NewState
= ~0;
188 swsetup
->InvalidateState
= _swsetup_invalidate_state
;
189 swsetup
->Quad
= _swsetup_validate_quad
;
190 swsetup
->Triangle
= _swsetup_validate_triangle
;
191 swsetup
->Line
= _swsetup_validate_line
;
192 swsetup
->Points
= _swsetup_validate_points
;
193 swsetup
->BuildProjVerts
= _swsetup_validate_buildprojverts
;
195 _swsetup_vb_init( ctx
);
196 _swsetup_trifuncs_init( ctx
);
202 _swsetup_DestroyContext( GLcontext
*ctx
)
204 if (SWSETUP_CONTEXT(ctx
)) {
205 if (SWSETUP_CONTEXT(ctx
)->verts
)
206 ALIGN_FREE(SWSETUP_CONTEXT(ctx
)->verts
);
208 FREE(SWSETUP_CONTEXT(ctx
));
209 ctx
->swsetup_context
= 0;