1 /* $Id: ss_context.c,v 1.2 2000/11/10 17:45:16 brianp 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"
42 /* Stub for swsetup->Triangle to select a true triangle function
43 * after a state change.
46 _swsetup_validate_quad( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
47 GLuint v2
, GLuint v3
, GLuint pv
)
49 _swsetup_choose_trifuncs( ctx
);
50 SWSETUP_CONTEXT(ctx
)->Quad( ctx
, v0
, v1
, v2
, v3
, pv
);
54 _swsetup_validate_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
55 GLuint v2
, GLuint pv
)
57 _swsetup_choose_trifuncs( ctx
);
58 SWSETUP_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
, pv
);
62 _swsetup_validate_line( GLcontext
*ctx
, GLuint v0
, GLuint v1
, GLuint pv
)
64 _swsetup_choose_trifuncs( ctx
);
65 SWSETUP_CONTEXT(ctx
)->Line( ctx
, v0
, v1
, pv
);
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_rastersetup( struct vertex_buffer
*VB
,
80 GLuint start
, GLuint end
)
82 GLcontext
*ctx
= VB
->ctx
;
83 _swsetup_choose_rastersetup_func( ctx
);
84 SWSETUP_CONTEXT(ctx
)->RasterSetup( VB
, start
, end
);
88 #define _SWSETUP_NEW_RASTERSETUP (_NEW_RENDERMODE| \
94 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
98 /* TODO: sleep/wakeup mechanism
101 _swsetup_sleep( GLcontext
*ctx
, GLuint new_state
)
107 _swsetup_invalidate_state( GLcontext
*ctx
, GLuint new_state
)
109 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
111 swsetup
->NewState
|= new_state
;
114 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
115 swsetup
->Triangle
= _swsetup_validate_triangle
;
116 swsetup
->Line
= _swsetup_validate_line
;
117 swsetup
->Points
= _swsetup_validate_points
;
118 swsetup
->Quad
= _swsetup_validate_quad
;
121 if (new_state
& _SWSETUP_NEW_RASTERSETUP
) {
122 swsetup
->RasterSetup
= _swsetup_validate_rastersetup
;
128 /* Dispatch from these fixed entrypoints to the state-dependent
132 _swsetup_Quad( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
133 GLuint v2
, GLuint v3
, GLuint pv
)
135 SWSETUP_CONTEXT(ctx
)->Quad( ctx
, v0
, v1
, v2
, v3
, pv
);
139 _swsetup_Triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
140 GLuint v2
, GLuint pv
)
142 SWSETUP_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
, pv
);
146 _swsetup_Line( GLcontext
*ctx
, GLuint v0
, GLuint v1
, GLuint pv
)
148 SWSETUP_CONTEXT(ctx
)->Line( ctx
, v0
, v1
, pv
);
153 _swsetup_Points( GLcontext
*ctx
, GLuint first
, GLuint last
)
155 SWSETUP_CONTEXT(ctx
)->Points( ctx
, first
, last
);
159 _swsetup_RasterSetup( struct vertex_buffer
*VB
, GLuint start
, GLuint end
)
161 SWSETUP_CONTEXT(VB
->ctx
)->RasterSetup( VB
, start
, end
);
165 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
167 SWSETUP_CONTEXT(ctx
)->InvalidateState( ctx
, new_state
);
172 _swsetup_CreateContext( GLcontext
*ctx
)
174 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
179 ctx
->swsetup_context
= swsetup
;
181 swsetup
->NewState
= ~0;
182 swsetup
->InvalidateState
= _swsetup_invalidate_state
;
183 swsetup
->Quad
= _swsetup_validate_quad
;
184 swsetup
->Triangle
= _swsetup_validate_triangle
;
185 swsetup
->Line
= _swsetup_validate_line
;
186 swsetup
->Points
= _swsetup_validate_points
;
187 swsetup
->RasterSetup
= _swsetup_validate_rastersetup
;
189 _swsetup_vb_init( ctx
);
190 _swsetup_trifuncs_init( ctx
);
196 _swsetup_DestroyContext( GLcontext
*ctx
)
198 if (SWSETUP_CONTEXT(ctx
)) {
199 FREE(SWSETUP_CONTEXT(ctx
));
200 ctx
->swsetup_context
= 0;
205 _swsetup_RegisterVB( struct vertex_buffer
*VB
)
207 SSvertexbuffer
*ssvb
= (SSvertexbuffer
*)CALLOC(sizeof(SSvertexbuffer
) );
209 ssvb
->verts
= ALIGN_MALLOC( sizeof(SWvertex
) * VB
->Size
, 32);
215 VB
->swsetup_vb
= ssvb
;
221 _swsetup_UnregisterVB( struct vertex_buffer
*VB
)
223 SSvertexbuffer
*ssvb
= SWSETUP_VB(VB
);
226 if (ssvb
->verts
) ALIGN_FREE(ssvb
->verts
);