Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
143 giacomo 1
/* $Id: ss_context.c,v 1.1 2003-04-29 12:46:51 giacomo Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  4.1
6
 *
7
 * Copyright (C) 1999-2002  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 <keith@tungstengraphics.com>
28
 */
29
 
30
#include "glheader.h"
31
#include "imports.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
GLboolean
53
_swsetup_CreateContext( GLcontext *ctx )
54
{
55
   TNLcontext *tnl = TNL_CONTEXT(ctx);
56
   SScontext *swsetup = (SScontext *)CALLOC(sizeof(SScontext));
57
 
58
   if (!swsetup)
59
      return GL_FALSE;
60
 
61
   swsetup->verts = (SWvertex *) ALIGN_CALLOC( sizeof(SWvertex) * tnl->vb.Size,
62
                                               32);
63
   if (!swsetup->verts) {
64
      FREE(swsetup);
65
      return GL_FALSE;
66
   }
67
 
68
   ctx->swsetup_context = swsetup;
69
 
70
   swsetup->NewState = ~0;
71
   _swsetup_vb_init( ctx );
72
   _swsetup_trifuncs_init( ctx );
73
 
74
   return GL_TRUE;
75
}
76
 
77
void
78
_swsetup_DestroyContext( GLcontext *ctx )
79
{
80
   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
81
 
82
   if (swsetup) {
83
      if (swsetup->verts)
84
         ALIGN_FREE(swsetup->verts);
85
 
86
      if (swsetup->ChanSecondaryColor.Ptr)
87
         ALIGN_FREE(swsetup->ChanSecondaryColor.Ptr);
88
 
89
      if (swsetup->ChanColor.Ptr)
90
         ALIGN_FREE(swsetup->ChanColor.Ptr);
91
 
92
      FREE(swsetup);
93
      ctx->swsetup_context = 0;
94
   }
95
}
96
 
97
static void
98
_swsetup_RenderPrimitive( GLcontext *ctx, GLenum mode )
99
{
100
   SWSETUP_CONTEXT(ctx)->render_prim = mode;
101
   _swrast_render_primitive( ctx, mode );
102
}
103
 
104
/*
105
 * We patch this function into tnl->Driver.Render.Start.
106
 * It's called when we start rendering a vertex buffer.
107
 */
108
static void
109
_swsetup_RenderStart( GLcontext *ctx )
110
{
111
   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
112
   GLuint new_state = swsetup->NewState;
113
 
114
   if (new_state & _SWSETUP_NEW_RENDERINDEX) {
115
      _swsetup_choose_trifuncs( ctx );
116
   }
117
 
118
   if (new_state & _SWSETUP_NEW_VERTS) {
119
      _swsetup_choose_rastersetup_func( ctx );
120
   }
121
 
122
   swsetup->NewState = 0;
123
 
124
   _swrast_render_start( ctx );
125
}
126
 
127
/*
128
 * We patch this function into tnl->Driver.Render.Finish.
129
 * It's called when we finish rendering a vertex buffer.
130
 */
131
static void
132
_swsetup_RenderFinish( GLcontext *ctx )
133
{
134
   _swrast_render_finish( ctx );
135
}
136
 
137
void
138
_swsetup_InvalidateState( GLcontext *ctx, GLuint new_state )
139
{
140
   SScontext *swsetup = SWSETUP_CONTEXT(ctx);
141
   swsetup->NewState |= new_state;
142
}
143
 
144
 
145
void
146
_swsetup_Wakeup( GLcontext *ctx )
147
{
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;
152
   /* interp */
153
   /* copypv */
154
   tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon; /* new */
155
   tnl->Driver.Render.ClippedLine = _tnl_RenderClippedLine; /* new */
156
   /* points */
157
   /* line */
158
   /* triangle */
159
   /* quad */
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;
163
   /* buildvertices */
164
   tnl->Driver.Render.Multipass = 0;
165
   _tnl_need_projected_coords( ctx, GL_TRUE );
166
   _swsetup_InvalidateState( ctx, ~0 );
167
}