1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_tris.c,v 1.8 2002/10/30 12:51:43 alanh Exp $ */ /* -*- c-basic-offset: 3 -*- */
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>
41 #include "swrast/swrast.h"
42 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_context.h"
45 #include "tnl/t_pipeline.h"
47 #include "r128_tris.h"
48 #include "r128_state.h"
51 #include "r128_ioctl.h"
53 static const GLuint hw_prim
[GL_POLYGON
+1] = {
54 R128_CCE_VC_CNTL_PRIM_TYPE_POINT
,
55 R128_CCE_VC_CNTL_PRIM_TYPE_LINE
,
56 R128_CCE_VC_CNTL_PRIM_TYPE_LINE
,
57 R128_CCE_VC_CNTL_PRIM_TYPE_LINE
,
58 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
59 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
60 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
61 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
62 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
63 R128_CCE_VC_CNTL_PRIM_TYPE_TRI_LIST
,
66 static void r128RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
);
67 static void r128RenderPrimitive( GLcontext
*ctx
, GLenum prim
);
70 /***********************************************************************
71 * Emit primitives as inline vertices *
72 ***********************************************************************/
74 #if defined(USE_X86_ASM)
75 #define COPY_DWORDS( j, vb, vertsize, v ) \
78 __asm__ __volatile__( "rep ; movsl" \
79 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
85 #define COPY_DWORDS( j, vb, vertsize, v ) \
87 for ( j = 0 ; j < vertsize ; j++ ) \
88 vb[j] = CPU_TO_LE32(((GLuint *)v)[j]); \
93 static __inline
void r128_draw_quad( r128ContextPtr rmesa
,
99 GLuint vertsize
= rmesa
->vertex_size
;
100 GLuint
*vb
= (GLuint
*)r128AllocDmaLow( rmesa
, 6 * vertsize
* 4 );
103 rmesa
->num_verts
+= 6;
104 COPY_DWORDS( j
, vb
, vertsize
, v0
);
105 COPY_DWORDS( j
, vb
, vertsize
, v1
);
106 COPY_DWORDS( j
, vb
, vertsize
, v3
);
107 COPY_DWORDS( j
, vb
, vertsize
, v1
);
108 COPY_DWORDS( j
, vb
, vertsize
, v2
);
109 COPY_DWORDS( j
, vb
, vertsize
, v3
);
113 static __inline
void r128_draw_triangle( r128ContextPtr rmesa
,
118 GLuint vertsize
= rmesa
->vertex_size
;
119 GLuint
*vb
= (GLuint
*)r128AllocDmaLow( rmesa
, 3 * vertsize
* 4 );
122 rmesa
->num_verts
+= 3;
123 COPY_DWORDS( j
, vb
, vertsize
, v0
);
124 COPY_DWORDS( j
, vb
, vertsize
, v1
);
125 COPY_DWORDS( j
, vb
, vertsize
, v2
);
128 static __inline
void r128_draw_line( r128ContextPtr rmesa
,
132 GLuint vertsize
= rmesa
->vertex_size
;
133 GLuint
*vb
= (GLuint
*)r128AllocDmaLow( rmesa
, 2 * vertsize
* 4 );
136 rmesa
->num_verts
+= 2;
137 COPY_DWORDS( j
, vb
, vertsize
, v0
);
138 COPY_DWORDS( j
, vb
, vertsize
, v1
);
141 static __inline
void r128_draw_point( r128ContextPtr rmesa
,
144 int vertsize
= rmesa
->vertex_size
;
145 GLuint
*vb
= (GLuint
*)r128AllocDmaLow( rmesa
, vertsize
* 4 );
148 rmesa
->num_verts
+= 1;
149 COPY_DWORDS( j
, vb
, vertsize
, v0
);
152 /***********************************************************************
153 * Macros for t_dd_tritmp.h to draw basic primitives *
154 ***********************************************************************/
156 #define TRI( a, b, c ) \
159 rmesa->draw_tri( rmesa, a, b, c ); \
161 r128_draw_triangle( rmesa, a, b, c ); \
164 #define QUAD( a, b, c, d ) \
167 rmesa->draw_tri( rmesa, a, b, d ); \
168 rmesa->draw_tri( rmesa, b, c, d ); \
170 r128_draw_quad( rmesa, a, b, c, d ); \
173 #define LINE( v0, v1 ) \
176 rmesa->draw_line( rmesa, v0, v1 ); \
178 r128_draw_line( rmesa, v0, v1 ); \
181 #define POINT( v0 ) \
184 rmesa->draw_point( rmesa, v0 ); \
186 r128_draw_point( rmesa, v0 ); \
190 /***********************************************************************
191 * Build render functions from dd templates *
192 ***********************************************************************/
194 #define R128_OFFSET_BIT 0x01
195 #define R128_TWOSIDE_BIT 0x02
196 #define R128_UNFILLED_BIT 0x04
197 #define R128_FALLBACK_BIT 0x08
198 #define R128_MAX_TRIFUNC 0x10
204 triangle_func triangle
;
206 } rast_tab
[R128_MAX_TRIFUNC
];
209 #define DO_FALLBACK (IND & R128_FALLBACK_BIT)
210 #define DO_OFFSET (IND & R128_OFFSET_BIT)
211 #define DO_UNFILLED (IND & R128_UNFILLED_BIT)
212 #define DO_TWOSIDE (IND & R128_TWOSIDE_BIT)
218 #define DO_FULL_QUAD 1
222 #define HAVE_BACK_COLORS 0
223 #define HAVE_HW_FLATSHADE 1
224 #define VERTEX r128Vertex
227 #define DEPTH_SCALE 1.0
228 #define UNFILLED_TRI unfilled_tri
229 #define UNFILLED_QUAD unfilled_quad
230 #define VERT_X(_v) _v->v.x
231 #define VERT_Y(_v) _v->v.y
232 #define VERT_Z(_v) _v->v.z
233 #define AREA_IS_CCW( a ) (a > 0)
234 #define GET_VERTEX(e) (rmesa->verts + (e<<rmesa->vertex_stride_shift))
236 #define VERT_SET_RGBA( v, c ) do { \
237 r128_color_t *vc = (r128_color_t *)&(v)->ui[coloroffset]; \
239 vc->green = (c)[1]; \
241 vc->alpha = (c)[3]; \
243 #define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]
244 #define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[coloroffset]
245 #define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]
247 #define VERT_SET_SPEC( v0, c ) if (havespec) { \
248 (v0)->v.specular.red = (c)[0];\
249 (v0)->v.specular.green = (c)[1];\
250 (v0)->v.specular.blue = (c)[2]; }
251 #define VERT_COPY_SPEC( v0, v1 ) if (havespec) { \
252 (v0)->v.specular.red = v1->v.specular.red; \
253 (v0)->v.specular.green = v1->v.specular.green; \
254 (v0)->v.specular.blue = v1->v.specular.blue; }
256 #define VERT_SAVE_SPEC( idx ) if (havespec) spec[idx] = v[idx]->ui[5]
257 #define VERT_RESTORE_SPEC( idx ) if (havespec) v[idx]->ui[5] = spec[idx]
259 #define LOCAL_VARS(n) \
260 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
261 GLuint color[n], spec[n]; \
262 GLuint coloroffset = (rmesa->vertex_size == 4 ? 3 : 4); \
263 GLboolean havespec = (rmesa->vertex_size == 4 ? 0 : 1); \
264 (void) color; (void) spec; (void) coloroffset; (void) havespec;
266 /***********************************************************************
267 * Helpers for rendering unfilled primitives *
268 ***********************************************************************/
270 #define RASTERIZE(x) if (rmesa->hw_primitive != hw_prim[x]) \
271 r128RasterPrimitive( ctx, hw_prim[x] )
272 #define RENDER_PRIMITIVE rmesa->render_primitive
273 #define IND R128_FALLBACK_BIT
275 #include "tnl_dd/t_dd_unfilled.h"
279 /***********************************************************************
280 * Generate GL render functions *
281 ***********************************************************************/
286 #include "tnl_dd/t_dd_tritmp.h"
288 #define IND (R128_OFFSET_BIT)
289 #define TAG(x) x##_offset
290 #include "tnl_dd/t_dd_tritmp.h"
292 #define IND (R128_TWOSIDE_BIT)
293 #define TAG(x) x##_twoside
294 #include "tnl_dd/t_dd_tritmp.h"
296 #define IND (R128_TWOSIDE_BIT|R128_OFFSET_BIT)
297 #define TAG(x) x##_twoside_offset
298 #include "tnl_dd/t_dd_tritmp.h"
300 #define IND (R128_UNFILLED_BIT)
301 #define TAG(x) x##_unfilled
302 #include "tnl_dd/t_dd_tritmp.h"
304 #define IND (R128_OFFSET_BIT|R128_UNFILLED_BIT)
305 #define TAG(x) x##_offset_unfilled
306 #include "tnl_dd/t_dd_tritmp.h"
308 #define IND (R128_TWOSIDE_BIT|R128_UNFILLED_BIT)
309 #define TAG(x) x##_twoside_unfilled
310 #include "tnl_dd/t_dd_tritmp.h"
312 #define IND (R128_TWOSIDE_BIT|R128_OFFSET_BIT|R128_UNFILLED_BIT)
313 #define TAG(x) x##_twoside_offset_unfilled
314 #include "tnl_dd/t_dd_tritmp.h"
316 #define IND (R128_FALLBACK_BIT)
317 #define TAG(x) x##_fallback
318 #include "tnl_dd/t_dd_tritmp.h"
320 #define IND (R128_OFFSET_BIT|R128_FALLBACK_BIT)
321 #define TAG(x) x##_offset_fallback
322 #include "tnl_dd/t_dd_tritmp.h"
324 #define IND (R128_TWOSIDE_BIT|R128_FALLBACK_BIT)
325 #define TAG(x) x##_twoside_fallback
326 #include "tnl_dd/t_dd_tritmp.h"
328 #define IND (R128_TWOSIDE_BIT|R128_OFFSET_BIT|R128_FALLBACK_BIT)
329 #define TAG(x) x##_twoside_offset_fallback
330 #include "tnl_dd/t_dd_tritmp.h"
332 #define IND (R128_UNFILLED_BIT|R128_FALLBACK_BIT)
333 #define TAG(x) x##_unfilled_fallback
334 #include "tnl_dd/t_dd_tritmp.h"
336 #define IND (R128_OFFSET_BIT|R128_UNFILLED_BIT|R128_FALLBACK_BIT)
337 #define TAG(x) x##_offset_unfilled_fallback
338 #include "tnl_dd/t_dd_tritmp.h"
340 #define IND (R128_TWOSIDE_BIT|R128_UNFILLED_BIT|R128_FALLBACK_BIT)
341 #define TAG(x) x##_twoside_unfilled_fallback
342 #include "tnl_dd/t_dd_tritmp.h"
344 #define IND (R128_TWOSIDE_BIT|R128_OFFSET_BIT|R128_UNFILLED_BIT| \
346 #define TAG(x) x##_twoside_offset_unfilled_fallback
347 #include "tnl_dd/t_dd_tritmp.h"
350 static void init_rast_tab( void )
355 init_twoside_offset();
357 init_offset_unfilled();
358 init_twoside_unfilled();
359 init_twoside_offset_unfilled();
361 init_offset_fallback();
362 init_twoside_fallback();
363 init_twoside_offset_fallback();
364 init_unfilled_fallback();
365 init_offset_unfilled_fallback();
366 init_twoside_unfilled_fallback();
367 init_twoside_offset_unfilled_fallback();
372 /***********************************************************************
373 * Rasterization fallback helpers *
374 ***********************************************************************/
377 /* This code is hit only when a mix of accelerated and unaccelerated
378 * primitives are being drawn, and only for the unaccelerated
382 r128_fallback_tri( r128ContextPtr rmesa
,
387 GLcontext
*ctx
= rmesa
->glCtx
;
389 r128_translate_vertex( ctx
, v0
, &v
[0] );
390 r128_translate_vertex( ctx
, v1
, &v
[1] );
391 r128_translate_vertex( ctx
, v2
, &v
[2] );
392 _swrast_Triangle( ctx
, &v
[0], &v
[1], &v
[2] );
397 r128_fallback_line( r128ContextPtr rmesa
,
401 GLcontext
*ctx
= rmesa
->glCtx
;
403 r128_translate_vertex( ctx
, v0
, &v
[0] );
404 r128_translate_vertex( ctx
, v1
, &v
[1] );
405 _swrast_Line( ctx
, &v
[0], &v
[1] );
410 r128_fallback_point( r128ContextPtr rmesa
,
413 GLcontext
*ctx
= rmesa
->glCtx
;
415 r128_translate_vertex( ctx
, v0
, &v
[0] );
416 _swrast_Point( ctx
, &v
[0] );
421 /**********************************************************************/
422 /* Render unclipped begin/end objects */
423 /**********************************************************************/
425 #define VERT(x) (r128Vertex *)(r128verts + (x << shift))
426 #define RENDER_POINTS( start, count ) \
427 for ( ; start < count ; start++) \
428 r128_draw_point( rmesa, VERT(start) )
429 #define RENDER_LINE( v0, v1 ) \
430 r128_draw_line( rmesa, VERT(v0), VERT(v1) )
431 #define RENDER_TRI( v0, v1, v2 ) \
432 r128_draw_triangle( rmesa, VERT(v0), VERT(v1), VERT(v2) )
433 #define RENDER_QUAD( v0, v1, v2, v3 ) \
434 r128_draw_quad( rmesa, VERT(v0), VERT(v1), VERT(v2), VERT(v3) )
435 #define INIT(x) do { \
436 if (0) fprintf(stderr, "%s\n", __FUNCTION__); \
437 r128RenderPrimitive( ctx, x ); \
441 r128ContextPtr rmesa = R128_CONTEXT(ctx); \
442 const GLuint shift = rmesa->vertex_stride_shift; \
443 const char *r128verts = (char *)rmesa->verts; \
444 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
446 #define RESET_STIPPLE
447 #define RESET_OCCLUSION
448 #define PRESERVE_VB_DEFS
450 #define TAG(x) r128_##x##_verts
451 #include "tnl/t_vb_rendertmp.h"
454 #define TAG(x) r128_##x##_elts
455 #define ELT(x) elt[x]
456 #include "tnl/t_vb_rendertmp.h"
459 /**********************************************************************/
460 /* Render clipped primitives */
461 /**********************************************************************/
463 static void r128RenderClippedPoly( GLcontext
*ctx
, const GLuint
*elts
,
466 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
467 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
469 /* Render the new vertices as an unclipped polygon.
472 GLuint
*tmp
= VB
->Elts
;
473 VB
->Elts
= (GLuint
*)elts
;
474 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
]( ctx
, 0, n
, PRIM_BEGIN
|PRIM_END
);
479 static void r128RenderClippedLine( GLcontext
*ctx
, GLuint ii
, GLuint jj
)
481 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
482 tnl
->Driver
.Render
.Line( ctx
, ii
, jj
);
485 static void r128FastRenderClippedPoly( GLcontext
*ctx
, const GLuint
*elts
,
488 r128ContextPtr rmesa
= R128_CONTEXT( ctx
);
489 GLuint vertsize
= rmesa
->vertex_size
;
490 GLuint
*vb
= r128AllocDmaLow( rmesa
, (n
-2) * 3 * 4 * vertsize
);
491 GLubyte
*r128verts
= (GLubyte
*)rmesa
->verts
;
492 const GLuint shift
= rmesa
->vertex_stride_shift
;
493 const GLuint
*start
= (const GLuint
*)VERT(elts
[0]);
496 rmesa
->num_verts
+= (n
-2) * 3;
498 for (i
= 2 ; i
< n
; i
++) {
499 COPY_DWORDS( j
, vb
, vertsize
, (r128VertexPtr
) VERT(elts
[i
-1]) );
500 COPY_DWORDS( j
, vb
, vertsize
, (r128VertexPtr
) VERT(elts
[i
]) );
501 COPY_DWORDS( j
, vb
, vertsize
, (r128VertexPtr
) start
);
508 /**********************************************************************/
509 /* Choose render functions */
510 /**********************************************************************/
512 #define _R128_NEW_RENDER_STATE (_DD_NEW_LINE_STIPPLE | \
513 _DD_NEW_LINE_SMOOTH | \
514 _DD_NEW_POINT_SMOOTH | \
515 _DD_NEW_TRI_SMOOTH | \
516 _DD_NEW_TRI_UNFILLED | \
517 _DD_NEW_TRI_LIGHT_TWOSIDE | \
518 _DD_NEW_TRI_OFFSET) \
521 #define POINT_FALLBACK (DD_POINT_SMOOTH)
522 #define LINE_FALLBACK (DD_LINE_STIPPLE|DD_LINE_SMOOTH)
523 #define TRI_FALLBACK (DD_TRI_SMOOTH)
524 #define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)
525 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)
528 static void r128ChooseRenderState(GLcontext
*ctx
)
530 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
531 GLuint flags
= ctx
->_TriangleCaps
;
534 if (flags
& (ANY_RASTER_FLAGS
|ANY_FALLBACK_FLAGS
)) {
535 rmesa
->draw_point
= r128_draw_point
;
536 rmesa
->draw_line
= r128_draw_line
;
537 rmesa
->draw_tri
= r128_draw_triangle
;
539 if (flags
& ANY_RASTER_FLAGS
) {
540 if (flags
& DD_TRI_LIGHT_TWOSIDE
) index
|= R128_TWOSIDE_BIT
;
541 if (flags
& DD_TRI_OFFSET
) index
|= R128_OFFSET_BIT
;
542 if (flags
& DD_TRI_UNFILLED
) index
|= R128_UNFILLED_BIT
;
545 /* Hook in fallbacks for specific primitives.
547 if (flags
& (POINT_FALLBACK
|LINE_FALLBACK
|TRI_FALLBACK
)) {
548 if (flags
& POINT_FALLBACK
) rmesa
->draw_point
= r128_fallback_point
;
549 if (flags
& LINE_FALLBACK
) rmesa
->draw_line
= r128_fallback_line
;
550 if (flags
& TRI_FALLBACK
) rmesa
->draw_tri
= r128_fallback_tri
;
551 index
|= R128_FALLBACK_BIT
;
555 if (index
!= rmesa
->RenderIndex
) {
556 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
557 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
558 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
559 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
560 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
563 tnl
->Driver
.Render
.PrimTabVerts
= r128_render_tab_verts
;
564 tnl
->Driver
.Render
.PrimTabElts
= r128_render_tab_elts
;
565 tnl
->Driver
.Render
.ClippedLine
= rast_tab
[index
].line
;
566 tnl
->Driver
.Render
.ClippedPolygon
= r128FastRenderClippedPoly
;
568 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
569 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
570 tnl
->Driver
.Render
.ClippedLine
= r128RenderClippedLine
;
571 tnl
->Driver
.Render
.ClippedPolygon
= r128RenderClippedPoly
;
574 rmesa
->RenderIndex
= index
;
578 /**********************************************************************/
579 /* Validate state at pipeline start */
580 /**********************************************************************/
582 static void r128RunPipeline( GLcontext
*ctx
)
584 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
586 if (rmesa
->new_state
|| rmesa
->NewGLState
& _NEW_TEXTURE
)
587 r128DDUpdateHWState( ctx
);
589 if (!rmesa
->Fallback
&& rmesa
->NewGLState
) {
590 if (rmesa
->NewGLState
& _R128_NEW_VERTEX_STATE
)
591 r128ChooseVertexState( ctx
);
593 if (rmesa
->NewGLState
& _R128_NEW_RENDER_STATE
)
594 r128ChooseRenderState( ctx
);
596 rmesa
->NewGLState
= 0;
599 _tnl_run_pipeline( ctx
);
602 /**********************************************************************/
603 /* High level hooks for t_vb_render.c */
604 /**********************************************************************/
606 /* This is called when Mesa switches between rendering triangle
607 * primitives (such as GL_POLYGON, GL_QUADS, GL_TRIANGLE_STRIP, etc),
608 * and lines, points and bitmaps.
610 * As the r128 uses triangles to render lines and points, it is
611 * necessary to turn off hardware culling when rendering these
615 static void r128RasterPrimitive( GLcontext
*ctx
, GLuint hwprim
)
617 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
619 rmesa
->setup
.dp_gui_master_cntl_c
&= ~R128_GMC_BRUSH_NONE
;
621 if ( ctx
->Polygon
.StippleFlag
&& hwprim
== GL_TRIANGLES
) {
622 rmesa
->setup
.dp_gui_master_cntl_c
|= R128_GMC_BRUSH_32x32_MONO_FG_LA
;
625 rmesa
->setup
.dp_gui_master_cntl_c
|= R128_GMC_BRUSH_SOLID_COLOR
;
628 rmesa
->new_state
|= R128_NEW_CONTEXT
;
629 rmesa
->dirty
|= R128_UPLOAD_CONTEXT
;
631 if (rmesa
->hw_primitive
!= hwprim
) {
632 FLUSH_BATCH( rmesa
);
633 rmesa
->hw_primitive
= hwprim
;
637 static void r128RenderPrimitive( GLcontext
*ctx
, GLenum prim
)
639 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
640 GLuint hw
= hw_prim
[prim
];
641 rmesa
->render_primitive
= prim
;
642 if (prim
>= GL_TRIANGLES
&& (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
644 r128RasterPrimitive( ctx
, hw
);
648 static void r128RenderStart( GLcontext
*ctx
)
650 /* Check for projective texturing. Make sure all texcoord
651 * pointers point to something. (fix in mesa?)
653 r128CheckTexSizes( ctx
);
656 static void r128RenderFinish( GLcontext
*ctx
)
658 if (R128_CONTEXT(ctx
)->RenderIndex
& R128_FALLBACK_BIT
)
659 _swrast_flush( ctx
);
663 /**********************************************************************/
664 /* Transition to/from hardware rasterization. */
665 /**********************************************************************/
667 void r128Fallback( GLcontext
*ctx
, GLuint bit
, GLboolean mode
)
669 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
670 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
671 GLuint oldfallback
= rmesa
->Fallback
;
674 rmesa
->Fallback
|= bit
;
675 if (oldfallback
== 0) {
676 FLUSH_BATCH( rmesa
);
677 _swsetup_Wakeup( ctx
);
678 rmesa
->RenderIndex
= ~0;
682 rmesa
->Fallback
&= ~bit
;
683 if (oldfallback
== bit
) {
684 _swrast_flush( ctx
);
685 tnl
->Driver
.Render
.Start
= r128RenderStart
;
686 tnl
->Driver
.Render
.PrimitiveNotify
= r128RenderPrimitive
;
687 tnl
->Driver
.Render
.Finish
= r128RenderFinish
;
688 tnl
->Driver
.Render
.BuildVertices
= r128BuildVertices
;
689 rmesa
->NewGLState
|= (_R128_NEW_RENDER_STATE
|
690 _R128_NEW_VERTEX_STATE
);
696 /**********************************************************************/
697 /* Initialization. */
698 /**********************************************************************/
700 void r128InitTriFuncs( GLcontext
*ctx
)
702 r128ContextPtr rmesa
= R128_CONTEXT(ctx
);
703 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
704 static int firsttime
= 1;
711 tnl
->Driver
.RunPipeline
= r128RunPipeline
;
712 tnl
->Driver
.Render
.Start
= r128RenderStart
;
713 tnl
->Driver
.Render
.Finish
= r128RenderFinish
;
714 tnl
->Driver
.Render
.PrimitiveNotify
= r128RenderPrimitive
;
715 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
716 tnl
->Driver
.Render
.BuildVertices
= r128BuildVertices
;
717 rmesa
->NewGLState
|= (_R128_NEW_RENDER_STATE
|
718 _R128_NEW_VERTEX_STATE
);
720 /* r128Fallback( ctx, 0x100000, 1 ); */