Lighting now emits colors as CHAN_TYPE, as it used to. This will require
[mesa.git] / src / mesa / swrast_setup / ss_context.c
1 /* $Id: ss_context.c,v 1.15 2001/07/17 19:39:32 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 *
26 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
28 */
29
30 #include "glheader.h"
31 #include "mem.h"
32 #include "ss_context.h"
33 #include "ss_triangle.h"
34 #include "ss_vb.h"
35 #include "swrast_setup.h"
36 #include "tnl/tnl.h"
37 #include "tnl/t_context.h"
38 #include "tnl/t_pipeline.h"
39
40
41 #define _SWSETUP_NEW_VERTS (_NEW_RENDERMODE| \
42 _NEW_POLYGON| \
43 _NEW_LIGHT| \
44 _NEW_TEXTURE| \
45 _NEW_COLOR| \
46 _NEW_FOG| \
47 _NEW_POINT)
48
49 #define _SWSETUP_NEW_RENDERINDEX (_NEW_POLYGON|_NEW_LIGHT)
50
51
52
53 GLboolean
54 _swsetup_CreateContext( GLcontext *ctx )
55 {
56 TNLcontext *tnl = TNL_CONTEXT(ctx);
57 SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
58
59 if (!swsetup)
60 return GL_FALSE;
61
62 swsetup->verts = (SWvertex *) ALIGN_MALLOC( sizeof(SWvertex) * tnl->vb.Size,
63 32);
64 if (!swsetup->verts) {
65 FREE(swsetup);
66 return GL_FALSE;
67 }
68
69 ctx->swsetup_context = swsetup;
70
71 swsetup->NewState = ~0;
72 _swsetup_vb_init( ctx );
73 _swsetup_trifuncs_init( ctx );
74
75 return GL_TRUE;
76 }
77
78 void
79 _swsetup_DestroyContext( GLcontext *ctx )
80 {
81 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
82
83 if (swsetup) {
84 if (swsetup->verts)
85 ALIGN_FREE(swsetup->verts);
86
87 if (swsetup->ChanSecondaryColor.Ptr)
88 ALIGN_FREE(swsetup->ChanSecondaryColor.Ptr);
89
90 if (swsetup->ChanColor.Ptr)
91 ALIGN_FREE(swsetup->ChanColor.Ptr);
92
93 FREE(swsetup);
94 ctx->swsetup_context = 0;
95 }
96 }
97
98 static void
99 _swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
100 {
101 SWSETUP_CONTEXT(ctx)->render_prim = mode;
102 }
103
104 static void
105 _swsetup_RenderStart( GLcontext *ctx )
106 {
107 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
108 GLuint new_state = swsetup->NewState;
109
110 if (new_state & _SWSETUP_NEW_RENDERINDEX) {
111 _swsetup_choose_trifuncs( ctx );
112 }
113
114 if (new_state & _SWSETUP_NEW_VERTS) {
115 _swsetup_choose_rastersetup_func( ctx );
116 }
117
118 swsetup->NewState = 0;
119
120 if (swsetup->Driver.Start)
121 swsetup->Driver.Start( ctx );
122 }
123
124 static void
125 _swsetup_RenderFinish( GLcontext *ctx )
126 {
127 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
128
129 _swrast_flush( ctx );
130
131 if (swsetup->Driver.Finish)
132 swsetup->Driver.Finish( ctx );
133 }
134
135 void
136 _swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
137 {
138 SScontext *swsetup = SWSETUP_CONTEXT(ctx);
139 swsetup->NewState |= new_state;
140 }
141
142
143 void
144 _swsetup_Wakeup( GLcontext *ctx )
145 {
146 TNLcontext *tnl = TNL_CONTEXT(ctx);
147 tnl->Driver.Render.Start = _swsetup_RenderStart;
148 tnl->Driver.Render.Finish = _swsetup_RenderFinish;
149 tnl->Driver.Render.PrimitiveNotify = _swsetup_RenderPrimitive;
150 /* interp */
151 /* copypv */
152 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */
153 tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */
154 /* points */
155 /* line */
156 /* triangle */
157 /* quad */
158 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;
159 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;
160 tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple;
161 /* buildvertices */
162 tnl->Driver.Render.Multipass = 0;
163 _tnl_need_projected_coords( ctx, GL_TRUE );
164 _swsetup_InvalidateState( ctx, ~0 );
165 }