def9e4f43c84dd4c0abce3137040d011d89405c2
1 /* $Id: ss_context.c,v 1.13 2001/03/12 00:48:43 gareth Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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 "ss_interp.h"
36 #include "swrast_setup.h"
37 #include "tnl/t_context.h"
40 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
47 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
50 /* Dispatch from these fixed entrypoints to the state-dependent
53 * The design of swsetup suggests that we could really program
54 * ctx->Driver.TriangleFunc directly from _swsetup_RenderStart, and
55 * avoid this second level of indirection. However, this is more
56 * convient for fallback cases in hardware rasterization drivers.
59 _swsetup_Quad( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
60 GLuint v2
, GLuint v3
)
62 SWSETUP_CONTEXT(ctx
)->Quad( ctx
, v0
, v1
, v2
, v3
);
66 _swsetup_Triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
69 SWSETUP_CONTEXT(ctx
)->Triangle( ctx
, v0
, v1
, v2
);
73 _swsetup_Line( GLcontext
*ctx
, GLuint v0
, GLuint v1
)
75 SWSETUP_CONTEXT(ctx
)->Line( ctx
, v0
, v1
);
79 _swsetup_Points( GLcontext
*ctx
, GLuint first
, GLuint last
)
81 SWSETUP_CONTEXT(ctx
)->Points( ctx
, first
, last
);
85 _swsetup_BuildProjectedVertices( GLcontext
*ctx
, GLuint start
, GLuint end
,
88 SWSETUP_CONTEXT(ctx
)->BuildProjVerts( ctx
, start
, end
, new_inputs
);
93 _swsetup_CreateContext( GLcontext
*ctx
)
95 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
96 SScontext
*swsetup
= (SScontext
*)CALLOC(sizeof(SScontext
));
101 swsetup
->verts
= (SWvertex
*) ALIGN_MALLOC( sizeof(SWvertex
) * tnl
->vb
.Size
, 32);
102 if (!swsetup
->verts
) {
107 ctx
->swsetup_context
= swsetup
;
109 swsetup
->NewState
= ~0;
110 _swsetup_vb_init( ctx
);
111 _swsetup_interp_init( ctx
);
112 _swsetup_trifuncs_init( ctx
);
118 _swsetup_DestroyContext( GLcontext
*ctx
)
120 if (SWSETUP_CONTEXT(ctx
)) {
121 if (SWSETUP_CONTEXT(ctx
)->verts
)
122 ALIGN_FREE(SWSETUP_CONTEXT(ctx
)->verts
);
124 FREE(SWSETUP_CONTEXT(ctx
));
125 ctx
->swsetup_context
= 0;
130 _swsetup_RenderPrimitive( GLcontext
*ctx
, GLenum mode
)
132 SWSETUP_CONTEXT(ctx
)->render_prim
= mode
;
136 _swsetup_RenderStart( GLcontext
*ctx
)
138 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
139 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
140 GLuint new_state
= swsetup
->NewState
;
142 if (new_state
& _SWSETUP_NEW_RENDERINDEX
) {
143 _swsetup_choose_trifuncs( ctx
);
146 if (new_state
& _SWSETUP_NEW_VERTS
) {
147 _swsetup_choose_rastersetup_func( ctx
);
150 swsetup
->NewState
= 0;
152 if (VB
->ClipMask
&& VB
->importable_data
)
153 VB
->import_data( ctx
,
155 VEC_NOT_WRITEABLE
|VEC_BAD_STRIDE
);
159 _swsetup_RenderFinish( GLcontext
*ctx
)
161 _swrast_flush( ctx
);
165 _swsetup_InvalidateState( GLcontext
*ctx
, GLuint new_state
)
167 SScontext
*swsetup
= SWSETUP_CONTEXT(ctx
);
168 swsetup
->NewState
|= new_state
;
170 if (new_state
& _SWSETUP_NEW_INTERP
) {
171 swsetup
->RenderInterp
= _swsetup_validate_interp
;
172 swsetup
->RenderCopyPV
= _swsetup_validate_copypv
;
177 _swsetup_RenderInterp( GLcontext
*ctx
, GLfloat t
,
178 GLuint dst
, GLuint out
, GLuint in
,
179 GLboolean force_boundary
)
181 SWSETUP_CONTEXT(ctx
)->RenderInterp( ctx
, t
, dst
, out
, in
, force_boundary
);
185 _swsetup_RenderCopyPV( GLcontext
*ctx
, GLuint dst
, GLuint src
)
187 SWSETUP_CONTEXT(ctx
)->RenderCopyPV( ctx
, dst
, src
);