Merge remote branch 'origin/master' into lp-binning
[mesa.git] / src / mesa / drivers / dri / mga / mgarender.c
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Keith Whitwell <keith@tungstengraphics.com>
32 *
33 */
34
35
36 /*
37 * Render unclipped vertex buffers by emitting vertices directly to
38 * dma buffers. Use strip/fan hardware primitives where possible.
39 * Simulate missing primitives with indexed vertices.
40 */
41 #include "main/glheader.h"
42 #include "main/context.h"
43 #include "main/macros.h"
44 #include "main/imports.h"
45 #include "main/mtypes.h"
46
47 #include "tnl/t_context.h"
48
49 #include "mgacontext.h"
50 #include "mgatris.h"
51 #include "mgaioctl.h"
52 #include "mgavb.h"
53
54 #define HAVE_POINTS 0
55 #define HAVE_LINES 0
56 #define HAVE_LINE_STRIPS 0
57 #define HAVE_TRIANGLES 1
58 #define HAVE_TRI_STRIPS 1
59 #define HAVE_TRI_STRIP_1 0
60 #define HAVE_TRI_FANS 1
61 #define HAVE_POLYGONS 0
62 #define HAVE_QUADS 0
63 #define HAVE_QUAD_STRIPS 0
64
65 #define HAVE_ELTS 0 /* for now */
66
67 static void mgaDmaPrimitive( GLcontext *ctx, GLenum prim )
68 {
69 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
70 GLuint hwprim;
71
72 switch (prim) {
73 case GL_TRIANGLES:
74 hwprim = MGA_WA_TRIANGLES;
75 break;
76 case GL_TRIANGLE_STRIP:
77 if (mmesa->vertex_size == 8)
78 hwprim = MGA_WA_TRISTRIP_T0;
79 else
80 hwprim = MGA_WA_TRISTRIP_T0T1;
81 break;
82 case GL_TRIANGLE_FAN:
83 if (mmesa->vertex_size == 8)
84 hwprim = MGA_WA_TRIFAN_T0;
85 else
86 hwprim = MGA_WA_TRIFAN_T0T1;
87 break;
88 default:
89 return;
90 }
91
92 mgaRasterPrimitive( ctx, GL_TRIANGLES, hwprim );
93 }
94
95
96 #define LOCAL_VARS mgaContextPtr mmesa = MGA_CONTEXT(ctx)
97 #define INIT( prim ) do { \
98 if (0) fprintf(stderr, "%s\n", __FUNCTION__); \
99 FLUSH_BATCH(mmesa); \
100 mgaDmaPrimitive( ctx, prim ); \
101 } while (0)
102 #define FLUSH() FLUSH_BATCH( mmesa )
103 #define GET_CURRENT_VB_MAX_VERTS() \
104 0 /* fix me */
105 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
106 MGA_BUFFER_SIZE / (mmesa->vertex_size * 4)
107
108
109 #define ALLOC_VERTS( nr ) \
110 mgaAllocDmaLow( mmesa, (nr) * mmesa->vertex_size * 4)
111 #define EMIT_VERTS( ctx, j, nr, buf ) \
112 mga_emit_contiguous_verts(ctx, j, (j)+(nr), buf)
113
114
115 #define TAG(x) mga_##x
116 #include "tnl_dd/t_dd_dmatmp.h"
117
118
119
120 /**********************************************************************/
121 /* Render pipeline stage */
122 /**********************************************************************/
123
124
125 static GLboolean mga_run_render( GLcontext *ctx,
126 struct tnl_pipeline_stage *stage )
127 {
128 mgaContextPtr mmesa = MGA_CONTEXT(ctx);
129 TNLcontext *tnl = TNL_CONTEXT(ctx);
130 struct vertex_buffer *VB = &tnl->vb;
131 GLuint i;
132
133 /* Don't handle clipping or indexed vertices or vertex manipulations.
134 */
135 if (mmesa->RenderIndex != 0 ||
136 !mga_validate_render( ctx, VB )) {
137 return GL_TRUE;
138 }
139
140 tnl->Driver.Render.Start( ctx );
141 mmesa->SetupNewInputs = ~0;
142
143 for (i = 0 ; i < VB->PrimitiveCount ; i++)
144 {
145 GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
146 GLuint start = VB->Primitive[i].start;
147 GLuint length = VB->Primitive[i].count;
148
149 if (!length)
150 continue;
151
152 mga_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
153 prim);
154 }
155
156 tnl->Driver.Render.Finish( ctx );
157
158 return GL_FALSE; /* finished the pipe */
159 }
160
161
162 const struct tnl_pipeline_stage _mga_render_stage =
163 {
164 "mga render",
165 NULL,
166 NULL,
167 NULL,
168 NULL,
169 mga_run_render /* run */
170 };