1 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgarender.c,v 1.4 2002/10/30 12:51:36 alanh Exp $ */
2 /**************************************************************************
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
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:
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
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.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
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.
48 #include "tnl/t_context.h"
50 #include "mgacontext.h"
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
65 #define HAVE_QUAD_STRIPS 0
67 #define HAVE_ELTS 0 /* for now */
69 static void mgaDmaPrimitive( GLcontext
*ctx
, GLenum prim
)
71 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
76 hwprim
= MGA_WA_TRIANGLES
;
78 case GL_TRIANGLE_STRIP
:
79 if (mmesa
->vertex_size
== 8)
80 hwprim
= MGA_WA_TRISTRIP_T0
;
82 hwprim
= MGA_WA_TRISTRIP_T0T1
;
85 if (mmesa
->vertex_size
== 8)
86 hwprim
= MGA_WA_TRIFAN_T0
;
88 hwprim
= MGA_WA_TRIFAN_T0T1
;
94 mgaRasterPrimitive( ctx
, GL_TRIANGLES
, hwprim
);
98 #define LOCAL_VARS mgaContextPtr mmesa = MGA_CONTEXT(ctx)
99 #define INIT( prim ) do { \
100 if (0) fprintf(stderr, "%s\n", __FUNCTION__); \
101 FLUSH_BATCH(mmesa); \
102 mgaDmaPrimitive( ctx, prim ); \
104 #define FLUSH() FLUSH_BATCH( mmesa )
105 #define GET_CURRENT_VB_MAX_VERTS() \
107 #define GET_SUBSEQUENT_VB_MAX_VERTS() \
108 MGA_BUFFER_SIZE / (mmesa->vertex_size * 4)
111 #define ALLOC_VERTS( nr ) \
112 mgaAllocDmaLow( mmesa, (nr) * mmesa->vertex_size * 4)
113 #define EMIT_VERTS( ctx, j, nr, buf ) \
114 mga_emit_contiguous_verts(ctx, j, (j)+(nr), buf)
117 #define TAG(x) mga_##x
118 #include "tnl_dd/t_dd_dmatmp.h"
122 /**********************************************************************/
123 /* Render pipeline stage */
124 /**********************************************************************/
127 static GLboolean
mga_run_render( GLcontext
*ctx
,
128 struct tnl_pipeline_stage
*stage
)
130 mgaContextPtr mmesa
= MGA_CONTEXT(ctx
);
131 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
132 struct vertex_buffer
*VB
= &tnl
->vb
;
135 /* Don't handle clipping or indexed vertices or vertex manipulations.
137 if (mmesa
->RenderIndex
!= 0 ||
138 !mga_validate_render( ctx
, VB
)) {
142 tnl
->Driver
.Render
.Start( ctx
);
143 mmesa
->SetupNewInputs
= ~0;
145 for (i
= 0 ; i
< VB
->PrimitiveCount
; i
++)
147 GLuint prim
= VB
->Primitive
[i
].mode
;
148 GLuint start
= VB
->Primitive
[i
].start
;
149 GLuint length
= VB
->Primitive
[i
].count
;
154 mga_render_tab_verts
[prim
& PRIM_MODE_MASK
]( ctx
, start
, start
+ length
,
158 tnl
->Driver
.Render
.Finish( ctx
);
160 return GL_FALSE
; /* finished the pipe */
164 static void mga_check_render( GLcontext
*ctx
, struct tnl_pipeline_stage
*stage
)
166 stage
->inputs
= TNL_CONTEXT(ctx
)->render_inputs
;
170 static void dtr( struct tnl_pipeline_stage
*stage
)
176 const struct tnl_pipeline_stage _mga_render_stage
=
179 (_DD_NEW_SEPARATE_SPECULAR
|
182 _NEW_RENDERMODE
), /* re-check (new inputs) */
183 0, /* re-run (always runs) */
184 GL_TRUE
, /* active */
185 0, 0, /* inputs (set in check_render), outputs */
186 0, 0, /* changed_inputs, private */
187 dtr
, /* destructor */
188 mga_check_render
, /* check - initially set to alloc data */
189 mga_run_render
/* run */