i915: Convert to using VBs instead of inline prims.
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_render.c
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #include "glheader.h"
6 #include "context.h"
7 #include "macros.h"
8 #include "mtypes.h"
9
10 #include "tnl/t_context.h"
11
12 #include "s3v_context.h"
13 #include "s3v_tris.h"
14 #include "s3v_vb.h"
15
16
17 #define HAVE_POINTS 0
18 #define HAVE_LINES 0
19 #define HAVE_LINE_STRIPS 0
20 #define HAVE_TRIANGLES 0
21 #define HAVE_TRI_STRIPS 0
22 #define HAVE_TRI_STRIP_1 0
23 #define HAVE_TRI_FANS 0
24 #define HAVE_QUADS 0
25 #define HAVE_QUAD_STRIPS 0
26 #define HAVE_POLYGONS 0
27
28 #define HAVE_ELTS 0
29
30 #if 0
31 static void VERT_FALLBACK( GLcontext *ctx,
32 GLuint start,
33 GLuint count,
34 GLuint flags )
35 {
36 TNLcontext *tnl = TNL_CONTEXT(ctx);
37 /* s3vContextPtr vmesa = S3V_CONTEXT(ctx); */
38 int _flags;
39
40 DEBUG(("VERT_FALLBACK: flags & PRIM_MODE_MASK = %i\n",
41 flags & PRIM_MODE_MASK));
42 DEBUG(("VERT_FALLBACK: flags=%i PRIM_MODE_MASK=%i\n",
43 flags, PRIM_MODE_MASK));
44 #if 0
45 tnl->Driver.Render.PrimitiveNotify( ctx, flags & PRIM_MODE_MASK );
46 #endif
47 tnl->Driver.Render.BuildVertices( ctx, start, count, ~0 );
48
49 _flags = flags & PRIM_MODE_MASK;
50
51 tnl->Driver.Render.PrimTabVerts[_flags]( ctx, start, count, flags );
52 S3V_CONTEXT(ctx)->SetupNewInputs = VERT_BIT_POS;
53 }
54 #endif
55
56 static const GLuint hw_prim[GL_POLYGON+1] = {
57 PrimType_Points,
58 PrimType_Lines,
59 PrimType_LineLoop,
60 PrimType_LineStrip,
61 PrimType_Triangles,
62 PrimType_TriangleStrip,
63 PrimType_TriangleFan,
64 PrimType_Quads,
65 PrimType_QuadStrip,
66 PrimType_Polygon
67 };
68
69 static __inline void s3vStartPrimitive( s3vContextPtr vmesa, GLenum prim )
70 {
71 __DRIdrawablePrivate *dPriv = vmesa->driDrawable;
72
73 int _hw_prim = hw_prim[prim];
74
75 DEBUG(("s3vStartPrimitive (new #%i) ", prim));
76
77 if (_hw_prim != vmesa->restore_primitive) {
78
79 if (prim == 4) { /* TRI */
80 DEBUG(("switching to tri\n"));
81 vmesa->prim_cmd = vmesa->_tri[vmesa->_3d_mode];
82 vmesa->alpha_cmd = vmesa->_alpha[vmesa->_3d_mode];
83 DMAOUT_CHECK(3DTRI_Z_BASE, 12);
84 } else if (prim == 1) { /* LINE */
85 DEBUG(("switching to line\n"));
86 vmesa->prim_cmd = DO_3D_LINE;
87 vmesa->alpha_cmd = vmesa->_alpha[0];
88 DMAOUT_CHECK(3DLINE_Z_BASE, 12);
89 } else {
90 DEBUG(("Never mind the bollocks!\n"));
91 }
92
93 DMAOUT(vmesa->s3vScreen->depthOffset & 0x003FFFF8);
94 DMAOUT(vmesa->DestBase);
95 /* DMAOUT(vmesa->ScissorLR); */
96 /* DMAOUT(vmesa->ScissorTB); */
97 DMAOUT( (0 << 16) | (dPriv->w-1) );
98 DMAOUT( (0 << 16) | (dPriv->h-1) );
99 DMAOUT( (vmesa->SrcStride << 16) | vmesa->TexStride );
100 DMAOUT(vmesa->SrcStride);
101 DMAOUT(vmesa->TexOffset);
102 DMAOUT(vmesa->TextureBorderColor);
103 DMAOUT(0); /* FOG */
104 DMAOUT(0);
105 DMAOUT(0);
106 DMAOUT(vmesa->CMD | vmesa->prim_cmd | vmesa->alpha_cmd);
107 DMAFINISH();
108 }
109
110 vmesa->restore_primitive = _hw_prim;
111 }
112
113 static __inline void s3vEndPrimitive( s3vContextPtr vmesa )
114 {
115 /* GLcontext *ctx = vmesa->glCtx; */
116 DEBUG(("s3vEndPrimitive\n"));
117 }
118
119 #define LOCAL_VARS s3vContextPtr vmesa = S3V_CONTEXT(ctx)
120 #define INIT( prim ) s3vStartPrimitive( vmesa, prim )
121 #define FINISH s3vEndPrimitive( vmesa )
122 #define NEW_PRIMITIVE() (void) vmesa
123 #define NEW_BUFFER() (void) vmesa
124 #define FIRE_VERTICES() (void) vmesa
125 #define GET_CURRENT_VB_MAX_VERTS() \
126 (vmesa->bufSize - vmesa->bufCount) / 2
127 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
128 S3V_DMA_BUF_SZ / 2
129 /* XXX */
130 #define ALLOC_VERTS(nr) NULL
131 #define EMIT_VERTS(ctx, start, count, buf) NULL
132 #define FLUSH() s3vEndPrimitive( vmesa )
133
134 #define TAG(x) s3v_##x
135
136 #include "tnl_dd/t_dd_dmatmp.h"
137
138 /**********************************************************************/
139 /* Render pipeline stage */
140 /**********************************************************************/
141
142
143 static GLboolean s3v_run_render( GLcontext *ctx,
144 struct tnl_pipeline_stage *stage )
145 {
146 s3vContextPtr vmesa = S3V_CONTEXT(ctx);
147 TNLcontext *tnl = TNL_CONTEXT(ctx);
148 struct vertex_buffer *VB = &tnl->vb;
149 GLuint i;
150 tnl_render_func *tab;
151
152 DEBUG(("s3v_run_render\n"));
153
154 /* FIXME: hw clip */
155 if (VB->ClipOrMask || vmesa->RenderIndex != 0) {
156 DEBUG(("*** CLIPPED in render ***\n"));
157 #if 1
158 return GL_TRUE; /* don't handle clipping here */
159 #endif
160 }
161
162
163 /* We don't do elts */
164 if (VB->Elts)
165 return GL_TRUE;
166
167 tab = TAG(render_tab_verts);
168
169 tnl->Driver.Render.Start( ctx );
170
171 for (i = 0 ; i < VB->PrimitiveCount ; i++ )
172 {
173 GLuint prim = _tnl_translate_prim(&VB->Primitive[i]);
174 GLuint start = VB->Primitive[i].start;
175 GLuint length = VB->Primitive[i].count;
176
177 DEBUG(("s3v_run_render (loop=%i) (lenght=%i)\n", i, length));
178
179 if (length) {
180 tnl->Driver.Render.BuildVertices( ctx, start,
181 start+length, ~0 /*stage->inputs*/); /* XXX */
182 tnl->Driver.Render.PrimTabVerts[prim & PRIM_MODE_MASK]
183 ( ctx, start, start + length, prim );
184 vmesa->SetupNewInputs = VERT_BIT_POS;
185 }
186 }
187
188 tnl->Driver.Render.Finish( ctx );
189
190 return GL_FALSE; /* finished the pipe */
191 }
192
193
194
195 const struct tnl_pipeline_stage _s3v_render_stage =
196 {
197 "s3v render",
198 NULL,
199 NULL,
200 NULL,
201 NULL,
202 s3v_run_render /* run */
203 };