5fb7af908c4c27e869d4db73efcd932c1e3a9849
[mesa.git] / src / mesa / drivers / dri / mga / mgarender.c
1 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgarender.c,v 1.4 2002/10/30 12:51:36 alanh Exp $ */
2 /**************************************************************************
3
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
6
7 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 on the rights to use, copy, modify, merge, publish, distribute, sub
13 license, and/or sell copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice (including the next
17 paragraph) shall be included in all copies or substantial portions of the
18 Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
24 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26 USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 *
34 */
35
36
37 /*
38 * Render unclipped vertex buffers by emitting vertices directly to
39 * dma buffers. Use strip/fan hardware primitives where possible.
40 * Simulate missing primitives with indexed vertices.
41 */
42 #include "glheader.h"
43 #include "context.h"
44 #include "macros.h"
45 #include "imports.h"
46 #include "mtypes.h"
47
48 #include "tnl/t_context.h"
49
50 #include "mgacontext.h"
51 #include "mgatris.h"
52 #include "mgastate.h"
53 #include "mgaioctl.h"
54 #include "mgavb.h"
55
56 #define HAVE_POINTS 0
57 #define HAVE_LINES 0
58 #define HAVE_LINE_STRIPS 0
59 #define HAVE_TRIANGLES 1
60 #define HAVE_TRI_STRIPS 1
61 #define HAVE_TRI_STRIP_1 0
62 #define HAVE_TRI_FANS 1
63 #define HAVE_POLYGONS 0
64 #define HAVE_QUADS 0
65 #define HAVE_QUAD_STRIPS 0
66
67 #define HAVE_ELTS 0 /* for now */
68
69 static void mgaDmaPrimitive( GLcontext *ctx, GLenum prim )
70 {
71 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
72 GLuint hwprim;
73
74 switch (prim) {
75 case GL_TRIANGLES:
76 hwprim = MGA_WA_TRIANGLES;
77 break;
78 case GL_TRIANGLE_STRIP:
79 if (mmesa->vertex_size == 8)
80 hwprim = MGA_WA_TRISTRIP_T0;
81 else
82 hwprim = MGA_WA_TRISTRIP_T0T1;
83 break;
84 case GL_TRIANGLE_FAN:
85 if (mmesa->vertex_size == 8)
86 hwprim = MGA_WA_TRIFAN_T0;
87 else
88 hwprim = MGA_WA_TRIFAN_T0T1;
89 break;
90 default:
91 return;
92 }
93
94 mgaRasterPrimitive( ctx, GL_TRIANGLES, hwprim );
95 }
96
97 static void VERT_FALLBACK( GLcontext *ctx, GLuint start, GLuint count,
98 GLuint flags )
99 {
100 TNLcontext *tnl = TNL_CONTEXT(ctx);
101 tnl->Driver.Render.PrimitiveNotify( ctx, flags & PRIM_MODE_MASK );
102 tnl->Driver.Render.BuildVertices( ctx, start, count, ~0 );
103 tnl->Driver.Render.PrimTabVerts[flags&PRIM_MODE_MASK]( ctx, start, count, flags );
104 MGA_CONTEXT(ctx)->SetupNewInputs |= VERT_BIT_POS;
105 }
106
107 #define LOCAL_VARS mgaContextPtr mmesa = MGA_CONTEXT(ctx)
108 #define INIT( prim ) do { \
109 if (0) fprintf(stderr, "%s\n", __FUNCTION__); \
110 FLUSH_BATCH(mmesa); \
111 mgaDmaPrimitive( ctx, prim ); \
112 } while (0)
113 #define NEW_PRIMITIVE() FLUSH_BATCH( mmesa )
114 #define NEW_BUFFER() FLUSH_BATCH( mmesa )
115 #define GET_CURRENT_VB_MAX_VERTS() \
116 0 /* fix me */
117 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
118 MGA_BUFFER_SIZE / (mmesa->vertex_size * 4)
119 #define EMIT_VERTS( ctx, j, nr ) \
120 mga_emit_contiguous_verts(ctx, j, (j)+(nr))
121
122
123 #define TAG(x) mga_##x
124 #include "tnl_dd/t_dd_dmatmp.h"
125
126
127
128 /**********************************************************************/
129 /* Render pipeline stage */
130 /**********************************************************************/
131
132
133 static GLboolean mga_run_render( GLcontext *ctx,
134 struct tnl_pipeline_stage *stage )
135 {
136 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
137 TNLcontext *tnl = TNL_CONTEXT(ctx);
138 struct vertex_buffer *VB = &tnl->vb;
139 GLuint i;
140
141 /* Don't handle clipping or indexed vertices or vertex manipulations.
142 */
143 if (VB->ClipOrMask || mmesa->RenderIndex != 0 || VB->Elts) {
144 return GL_TRUE;
145 }
146
147 tnl->Driver.Render.Start( ctx );
148 mmesa->SetupNewInputs = ~0;
149
150 for (i = 0 ; i < VB->PrimitiveCount ; i++)
151 {
152 GLuint prim = VB->Primitive[i].mode;
153 GLuint start = VB->Primitive[i].start;
154 GLuint length = VB->Primitive[i].count;
155
156 if (!length)
157 continue;
158
159 mga_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
160 prim);
161 }
162
163 tnl->Driver.Render.Finish( ctx );
164
165 return GL_FALSE; /* finished the pipe */
166 }
167
168
169 static void mga_check_render( GLcontext *ctx, struct tnl_pipeline_stage *stage )
170 {
171 GLuint inputs = VERT_BIT_POS | VERT_BIT_COLOR0;
172
173 if (ctx->RenderMode == GL_RENDER) {
174 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
175 inputs |= VERT_BIT_COLOR1;
176
177 if (ctx->Texture.Unit[0]._ReallyEnabled)
178 inputs |= VERT_BIT_TEX0;
179
180 if (ctx->Texture.Unit[1]._ReallyEnabled)
181 inputs |= VERT_BIT_TEX1;
182
183 if (ctx->Fog.Enabled)
184 inputs |= VERT_BIT_FOG;
185 }
186
187 stage->inputs = inputs;
188 }
189
190
191 static void dtr( struct tnl_pipeline_stage *stage )
192 {
193 (void)stage;
194 }
195
196
197 const struct tnl_pipeline_stage _mga_render_stage =
198 {
199 "mga render",
200 (_DD_NEW_SEPARATE_SPECULAR |
201 _NEW_TEXTURE|
202 _NEW_FOG|
203 _NEW_RENDERMODE), /* re-check (new inputs) */
204 0, /* re-run (always runs) */
205 GL_TRUE, /* active */
206 0, 0, /* inputs (set in check_render), outputs */
207 0, 0, /* changed_inputs, private */
208 dtr, /* destructor */
209 mga_check_render, /* check - initially set to alloc data */
210 mga_run_render /* run */
211 };