Import vtx-0-2-branch
[mesa.git] / src / mesa / drivers / dri / i810 / i810render.c
1 /*
2 * Intel i810 DRI driver for Mesa 3.5
3 *
4 * Copyright (C) 1999-2000 Keith Whitwell All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL KEITH WHITWELL BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Author:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 */
27
28
29 /*
30 * Render unclipped vertex buffers by emitting vertices directly to
31 * dma buffers. Use strip/fan hardware acceleration where possible.
32 *
33 */
34 #include "glheader.h"
35 #include "context.h"
36 #include "macros.h"
37 #include "imports.h"
38 #include "mtypes.h"
39
40 #include "tnl/t_context.h"
41
42 #include "i810screen.h"
43 #include "i810_dri.h"
44
45 #include "i810context.h"
46 #include "i810tris.h"
47 #include "i810state.h"
48 #include "i810vb.h"
49 #include "i810ioctl.h"
50
51 /*
52 * Render unclipped vertex buffers by emitting vertices directly to
53 * dma buffers. Use strip/fan hardware primitives where possible.
54 * Try to simulate missing primitives with indexed vertices.
55 */
56 #define HAVE_POINTS 0
57 #define HAVE_LINES 1
58 #define HAVE_LINE_STRIPS 1
59 #define HAVE_TRIANGLES 1
60 #define HAVE_TRI_STRIPS 1
61 #define HAVE_TRI_STRIP_1 0 /* has it, template can't use it yet */
62 #define HAVE_TRI_FANS 1
63 #define HAVE_POLYGONS 1
64 #define HAVE_QUADS 0
65 #define HAVE_QUAD_STRIPS 0
66
67 #define HAVE_ELTS 0
68
69
70 static GLuint hw_prim[GL_POLYGON+1] = {
71 0,
72 PR_LINES,
73 0,
74 PR_LINESTRIP,
75 PR_TRIANGLES,
76 PR_TRISTRIP_0,
77 PR_TRIFAN,
78 0,
79 0,
80 PR_POLYGON
81 };
82
83 static const GLenum reduced_prim[GL_POLYGON+1] = {
84 GL_POINTS,
85 GL_LINES,
86 GL_LINES,
87 GL_LINES,
88 GL_TRIANGLES,
89 GL_TRIANGLES,
90 GL_TRIANGLES,
91 GL_TRIANGLES,
92 GL_TRIANGLES,
93 GL_TRIANGLES
94 };
95
96 /* Fallback to normal rendering.
97 */
98 static void VERT_FALLBACK( GLcontext *ctx,
99 GLuint start,
100 GLuint count,
101 GLuint flags )
102 {
103 TNLcontext *tnl = TNL_CONTEXT(ctx);
104 tnl->Driver.Render.PrimitiveNotify( ctx, flags & PRIM_MODE_MASK );
105 tnl->Driver.Render.BuildVertices( ctx, start, count, ~0 );
106 tnl->Driver.Render.PrimTabVerts[flags&PRIM_MODE_MASK]( ctx, start,
107 count, flags );
108 I810_CONTEXT(ctx)->SetupNewInputs = VERT_BIT_POS;
109 }
110
111
112
113 #define LOCAL_VARS i810ContextPtr imesa = I810_CONTEXT(ctx)
114 #define INIT( prim ) do { \
115 I810_STATECHANGE(imesa, 0); \
116 i810RasterPrimitive( ctx, reduced_prim[prim], hw_prim[prim] ); \
117 } while (0)
118 #define NEW_PRIMITIVE() I810_STATECHANGE( imesa, 0 )
119 #define NEW_BUFFER() I810_FIREVERTICES( imesa )
120 #define GET_CURRENT_VB_MAX_VERTS() \
121 (((int)imesa->vertex_high - (int)imesa->vertex_low) / (imesa->vertex_size*4))
122 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
123 (I810_DMA_BUF_SZ-4) / (imesa->vertex_size * 4)
124
125
126 #define EMIT_VERTS( ctx, j, nr ) \
127 i810_emit_contiguous_verts(ctx, j, (j)+(nr))
128
129
130 #define TAG(x) i810_##x
131 #include "tnl_dd/t_dd_dmatmp.h"
132
133
134 /**********************************************************************/
135 /* Render pipeline stage */
136 /**********************************************************************/
137
138
139 static GLboolean i810_run_render( GLcontext *ctx,
140 struct tnl_pipeline_stage *stage )
141 {
142 i810ContextPtr imesa = I810_CONTEXT(ctx);
143 TNLcontext *tnl = TNL_CONTEXT(ctx);
144 struct vertex_buffer *VB = &tnl->vb;
145 GLuint i;
146
147 /* Don't handle clipping or indexed vertices.
148 */
149 if (VB->ClipOrMask || imesa->RenderIndex != 0 || VB->Elts) {
150 return GL_TRUE;
151 }
152
153 imesa->SetupNewInputs = VERT_BIT_POS;
154
155 tnl->Driver.Render.Start( ctx );
156
157 for (i = 0 ; i < VB->PrimitiveCount ; i++)
158 {
159 GLuint prim = VB->Primitive[i].mode;
160 GLuint start = VB->Primitive[i].start;
161 GLuint length = VB->Primitive[i].count;
162
163 if (!length)
164 continue;
165
166 i810_render_tab_verts[prim & PRIM_MODE_MASK]( ctx, start, start + length,
167 prim );
168 }
169
170 tnl->Driver.Render.Finish( ctx );
171
172 return GL_FALSE; /* finished the pipe */
173 }
174
175
176 static void i810_check_render( GLcontext *ctx, struct tnl_pipeline_stage *stage )
177 {
178 GLuint inputs = VERT_BIT_POS | VERT_BIT_COLOR0;
179
180 if (ctx->RenderMode == GL_RENDER) {
181 if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR)
182 inputs |= VERT_BIT_COLOR1;
183
184 if (ctx->Texture.Unit[0]._ReallyEnabled)
185 inputs |= VERT_BIT_TEX0;
186
187 if (ctx->Texture.Unit[1]._ReallyEnabled)
188 inputs |= VERT_BIT_TEX1;
189
190 if (ctx->Fog.Enabled)
191 inputs |= VERT_BIT_FOG;
192 }
193
194 stage->inputs = inputs;
195 }
196
197
198 static void dtr( struct tnl_pipeline_stage *stage )
199 {
200 (void)stage;
201 }
202
203
204 const struct tnl_pipeline_stage _i810_render_stage =
205 {
206 "i810 render",
207 (_DD_NEW_SEPARATE_SPECULAR |
208 _NEW_TEXTURE|
209 _NEW_FOG|
210 _NEW_RENDERMODE), /* re-check (new inputs) */
211 0, /* re-run (always runs) */
212 GL_TRUE, /* active */
213 0, 0, /* inputs (set in check_render), outputs */
214 0, 0, /* changed_inputs, private */
215 dtr, /* destructor */
216 i810_check_render, /* check - initially set to alloc data */
217 i810_run_render /* run */
218 };