1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
38 #include "tnl/t_context.h"
39 #include "tnl/t_pipeline.h"
40 #include "tnl/t_vertex.h"
42 #include "intel_screen.h"
43 #include "intel_context.h"
44 #include "intel_tris.h"
45 #include "intel_batchbuffer.h"
46 #include "intel_buffers.h"
47 #include "intel_reg.h"
48 #include "intel_span.h"
49 #include "intel_tex.h"
51 static void intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
);
52 static void intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
,
58 intel_flush_inline_primitive(struct intel_context
*intel
)
60 GLuint used
= intel
->batch
->ptr
- intel
->prim
.start_ptr
;
62 assert(intel
->prim
.primitive
!= ~0);
64 /* _mesa_printf("/\n"); */
69 *(int *) intel
->prim
.start_ptr
= (_3DPRIMITIVE
|
70 intel
->prim
.primitive
| (used
/ 4 - 2));
75 intel
->batch
->ptr
-= used
;
78 intel
->prim
.primitive
= ~0;
79 intel
->prim
.start_ptr
= 0;
80 intel
->prim
.flush
= 0;
84 /* Emit a primitive referencing vertices in a vertex buffer.
87 intelStartInlinePrimitive(struct intel_context
*intel
,
88 GLuint prim
, GLuint batch_flags
)
92 intel
->vtbl
.emit_state(intel
);
94 /* Need to make sure at the very least that we don't wrap
95 * batchbuffers in BEGIN_BATCH below, otherwise the primitive will
96 * be emitted to a batchbuffer missing the required full-state
99 if (intel_batchbuffer_space(intel
->batch
) < 100) {
100 intel_batchbuffer_flush(intel
->batch
);
101 intel
->vtbl
.emit_state(intel
);
104 /* _mesa_printf("%s *", __progname); */
106 intel_wait_flips(intel
, batch_flags
);
108 /* Emit a slot which will be filled with the inline primitive
111 BEGIN_BATCH(2, batch_flags
);
114 assert(intel
->batch
->id
== intel
->last_state_batch_id
);
115 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
117 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
118 intel
->prim
.primitive
= prim
;
119 intel
->prim
.flush
= intel_flush_inline_primitive
;
124 /* _mesa_printf(">"); */
129 intelWrapInlinePrimitive(struct intel_context
*intel
)
131 GLuint prim
= intel
->prim
.primitive
;
132 GLuint batchflags
= intel
->batch
->flags
;
134 intel_flush_inline_primitive(intel
);
135 intel_batchbuffer_flush(intel
->batch
);
136 intelStartInlinePrimitive(intel
, prim
, batchflags
); /* ??? */
140 intelExtendInlinePrimitive(struct intel_context
*intel
, GLuint dwords
)
142 GLuint sz
= dwords
* sizeof(GLuint
);
145 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
147 if (intel_batchbuffer_space(intel
->batch
) < sz
)
148 intelWrapInlinePrimitive(intel
);
150 /* _mesa_printf("."); */
152 intel
->vtbl
.assert_not_dirty(intel
);
154 ptr
= (GLuint
*) intel
->batch
->ptr
;
155 intel
->batch
->ptr
+= sz
;
162 /***********************************************************************
163 * Emit primitives as inline vertices *
164 ***********************************************************************/
167 #define COPY_DWORDS( j, vb, vertsize, v ) \
170 __asm__ __volatile__( "rep ; movsl" \
171 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
177 #define COPY_DWORDS( j, vb, vertsize, v ) \
179 for ( j = 0 ; j < vertsize ; j++ ) { \
180 vb[j] = ((GLuint *)v)[j]; \
187 intel_draw_quad(struct intel_context
*intel
,
189 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
191 GLuint vertsize
= intel
->vertex_size
;
192 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 6 * vertsize
);
195 COPY_DWORDS(j
, vb
, vertsize
, v0
);
196 COPY_DWORDS(j
, vb
, vertsize
, v1
);
198 /* If smooth shading, draw like a trifan which gives better
199 * rasterization. Otherwise draw as two triangles with provoking
200 * vertex in third position as required for flat shading.
202 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
203 COPY_DWORDS(j
, vb
, vertsize
, v3
);
204 COPY_DWORDS(j
, vb
, vertsize
, v1
);
207 COPY_DWORDS(j
, vb
, vertsize
, v2
);
208 COPY_DWORDS(j
, vb
, vertsize
, v0
);
211 COPY_DWORDS(j
, vb
, vertsize
, v2
);
212 COPY_DWORDS(j
, vb
, vertsize
, v3
);
216 intel_draw_triangle(struct intel_context
*intel
,
217 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
219 GLuint vertsize
= intel
->vertex_size
;
220 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 3 * vertsize
);
223 COPY_DWORDS(j
, vb
, vertsize
, v0
);
224 COPY_DWORDS(j
, vb
, vertsize
, v1
);
225 COPY_DWORDS(j
, vb
, vertsize
, v2
);
230 intel_draw_line(struct intel_context
*intel
,
231 intelVertexPtr v0
, intelVertexPtr v1
)
233 GLuint vertsize
= intel
->vertex_size
;
234 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 2 * vertsize
);
237 COPY_DWORDS(j
, vb
, vertsize
, v0
);
238 COPY_DWORDS(j
, vb
, vertsize
, v1
);
243 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
245 GLuint vertsize
= intel
->vertex_size
;
246 GLuint
*vb
= intelExtendInlinePrimitive(intel
, vertsize
);
249 /* Adjust for sub pixel position -- still required for conform. */
250 *(float *) &vb
[0] = v0
->v
.x
- 0.125;
251 *(float *) &vb
[1] = v0
->v
.y
- 0.125;
252 for (j
= 2; j
< vertsize
; j
++)
258 /***********************************************************************
259 * Fixup for ARB_point_parameters *
260 ***********************************************************************/
262 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
263 * represented in the fragment program InputsRead field.
266 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
268 GLcontext
*ctx
= &intel
->ctx
;
269 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
271 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
272 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
274 restore_psz
= psz
[0];
275 restore_alpha
= col
[3];
277 if (psz
[0] >= ctx
->Point
.Threshold
) {
278 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
281 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
282 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
283 col
[3] *= dsize
* dsize
;
289 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
290 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
291 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
293 intel_draw_point(intel
, v0
);
295 psz
[0] = restore_psz
;
296 col
[3] = restore_alpha
;
298 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
299 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
302 intel_draw_point(intel
, v0
);
309 /***********************************************************************
310 * Fixup for I915 WPOS texture coordinate *
311 ***********************************************************************/
316 intel_wpos_triangle(struct intel_context
*intel
,
317 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
319 GLuint offset
= intel
->wpos_offset
;
320 GLuint size
= intel
->wpos_size
;
322 __memcpy(((char *) v0
) + offset
, v0
, size
);
323 __memcpy(((char *) v1
) + offset
, v1
, size
);
324 __memcpy(((char *) v2
) + offset
, v2
, size
);
326 intel_draw_triangle(intel
, v0
, v1
, v2
);
331 intel_wpos_line(struct intel_context
*intel
,
332 intelVertexPtr v0
, intelVertexPtr v1
)
334 GLuint offset
= intel
->wpos_offset
;
335 GLuint size
= intel
->wpos_size
;
337 __memcpy(((char *) v0
) + offset
, v0
, size
);
338 __memcpy(((char *) v1
) + offset
, v1
, size
);
340 intel_draw_line(intel
, v0
, v1
);
345 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
347 GLuint offset
= intel
->wpos_offset
;
348 GLuint size
= intel
->wpos_size
;
350 __memcpy(((char *) v0
) + offset
, v0
, size
);
352 intel_draw_point(intel
, v0
);
360 /***********************************************************************
361 * Macros for t_dd_tritmp.h to draw basic primitives *
362 ***********************************************************************/
364 #define TRI( a, b, c ) \
367 intel->draw_tri( intel, a, b, c ); \
369 intel_draw_triangle( intel, a, b, c ); \
372 #define QUAD( a, b, c, d ) \
375 intel->draw_tri( intel, a, b, d ); \
376 intel->draw_tri( intel, b, c, d ); \
378 intel_draw_quad( intel, a, b, c, d ); \
381 #define LINE( v0, v1 ) \
384 intel->draw_line( intel, v0, v1 ); \
386 intel_draw_line( intel, v0, v1 ); \
389 #define POINT( v0 ) \
392 intel->draw_point( intel, v0 ); \
394 intel_draw_point( intel, v0 ); \
398 /***********************************************************************
399 * Build render functions from dd templates *
400 ***********************************************************************/
402 #define INTEL_OFFSET_BIT 0x01
403 #define INTEL_TWOSIDE_BIT 0x02
404 #define INTEL_UNFILLED_BIT 0x04
405 #define INTEL_FALLBACK_BIT 0x08
406 #define INTEL_MAX_TRIFUNC 0x10
411 tnl_points_func points
;
413 tnl_triangle_func triangle
;
415 } rast_tab
[INTEL_MAX_TRIFUNC
];
418 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
419 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
420 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
421 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
427 #define DO_FULL_QUAD 1
431 #define HAVE_BACK_COLORS 0
432 #define HAVE_HW_FLATSHADE 1
433 #define VERTEX intelVertex
436 /* Only used to pull back colors into vertices (ie, we know color is
439 #define INTEL_COLOR( dst, src ) \
441 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
442 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
443 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
444 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
447 #define INTEL_SPEC( dst, src ) \
449 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
450 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
451 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
455 #define DEPTH_SCALE intel->polygon_offset_scale
456 #define UNFILLED_TRI unfilled_tri
457 #define UNFILLED_QUAD unfilled_quad
458 #define VERT_X(_v) _v->v.x
459 #define VERT_Y(_v) _v->v.y
460 #define VERT_Z(_v) _v->v.z
461 #define AREA_IS_CCW( a ) (a > 0)
462 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
464 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
465 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
466 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
467 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
469 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
470 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
471 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
472 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
474 #define LOCAL_VARS(n) \
475 struct intel_context *intel = intel_context(ctx); \
476 GLuint color[n], spec[n]; \
477 GLuint coloroffset = intel->coloroffset; \
478 GLboolean specoffset = intel->specoffset; \
479 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
482 /***********************************************************************
483 * Helpers for rendering unfilled primitives *
484 ***********************************************************************/
486 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
499 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
500 #define RENDER_PRIMITIVE intel->render_primitive
502 #define IND INTEL_FALLBACK_BIT
503 #include "tnl_dd/t_dd_unfilled.h"
506 /***********************************************************************
507 * Generate GL render functions *
508 ***********************************************************************/
512 #include "tnl_dd/t_dd_tritmp.h"
514 #define IND (INTEL_OFFSET_BIT)
515 #define TAG(x) x##_offset
516 #include "tnl_dd/t_dd_tritmp.h"
518 #define IND (INTEL_TWOSIDE_BIT)
519 #define TAG(x) x##_twoside
520 #include "tnl_dd/t_dd_tritmp.h"
522 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
523 #define TAG(x) x##_twoside_offset
524 #include "tnl_dd/t_dd_tritmp.h"
526 #define IND (INTEL_UNFILLED_BIT)
527 #define TAG(x) x##_unfilled
528 #include "tnl_dd/t_dd_tritmp.h"
530 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
531 #define TAG(x) x##_offset_unfilled
532 #include "tnl_dd/t_dd_tritmp.h"
534 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
535 #define TAG(x) x##_twoside_unfilled
536 #include "tnl_dd/t_dd_tritmp.h"
538 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
539 #define TAG(x) x##_twoside_offset_unfilled
540 #include "tnl_dd/t_dd_tritmp.h"
542 #define IND (INTEL_FALLBACK_BIT)
543 #define TAG(x) x##_fallback
544 #include "tnl_dd/t_dd_tritmp.h"
546 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
547 #define TAG(x) x##_offset_fallback
548 #include "tnl_dd/t_dd_tritmp.h"
550 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
551 #define TAG(x) x##_twoside_fallback
552 #include "tnl_dd/t_dd_tritmp.h"
554 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
555 #define TAG(x) x##_twoside_offset_fallback
556 #include "tnl_dd/t_dd_tritmp.h"
558 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
559 #define TAG(x) x##_unfilled_fallback
560 #include "tnl_dd/t_dd_tritmp.h"
562 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
563 #define TAG(x) x##_offset_unfilled_fallback
564 #include "tnl_dd/t_dd_tritmp.h"
566 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
567 #define TAG(x) x##_twoside_unfilled_fallback
568 #include "tnl_dd/t_dd_tritmp.h"
570 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
572 #define TAG(x) x##_twoside_offset_unfilled_fallback
573 #include "tnl_dd/t_dd_tritmp.h"
582 init_twoside_offset();
584 init_offset_unfilled();
585 init_twoside_unfilled();
586 init_twoside_offset_unfilled();
588 init_offset_fallback();
589 init_twoside_fallback();
590 init_twoside_offset_fallback();
591 init_unfilled_fallback();
592 init_offset_unfilled_fallback();
593 init_twoside_unfilled_fallback();
594 init_twoside_offset_unfilled_fallback();
598 /***********************************************************************
599 * Rasterization fallback helpers *
600 ***********************************************************************/
603 /* This code is hit only when a mix of accelerated and unaccelerated
604 * primitives are being drawn, and only for the unaccelerated
608 intel_fallback_tri(struct intel_context
*intel
,
609 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
611 GLcontext
*ctx
= &intel
->ctx
;
615 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
617 INTEL_FIREVERTICES(intel
);
619 _swsetup_Translate(ctx
, v0
, &v
[0]);
620 _swsetup_Translate(ctx
, v1
, &v
[1]);
621 _swsetup_Translate(ctx
, v2
, &v
[2]);
622 intelSpanRenderStart(ctx
);
623 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
624 intelSpanRenderFinish(ctx
);
629 intel_fallback_line(struct intel_context
*intel
,
630 intelVertex
* v0
, intelVertex
* v1
)
632 GLcontext
*ctx
= &intel
->ctx
;
636 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
638 INTEL_FIREVERTICES(intel
);
640 _swsetup_Translate(ctx
, v0
, &v
[0]);
641 _swsetup_Translate(ctx
, v1
, &v
[1]);
642 intelSpanRenderStart(ctx
);
643 _swrast_Line(ctx
, &v
[0], &v
[1]);
644 intelSpanRenderFinish(ctx
);
648 intel_fallback_point(struct intel_context
*intel
,
651 GLcontext
*ctx
= &intel
->ctx
;
655 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
657 INTEL_FIREVERTICES(intel
);
659 _swsetup_Translate(ctx
, v0
, &v
[0]);
660 intelSpanRenderStart(ctx
);
661 _swrast_Point(ctx
, &v
[0]);
662 intelSpanRenderFinish(ctx
);
666 /**********************************************************************/
667 /* Render unclipped begin/end objects */
668 /**********************************************************************/
671 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
672 #define RENDER_POINTS( start, count ) \
673 for ( ; start < count ; start++) POINT( V(ELT(start)) );
674 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
675 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
676 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
677 #define INIT(x) intelRenderPrimitive( ctx, x )
680 struct intel_context *intel = intel_context(ctx); \
681 GLubyte *vertptr = (GLubyte *)intel->verts; \
682 const GLuint vertsize = intel->vertex_size; \
683 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
685 #define RESET_STIPPLE
686 #define RESET_OCCLUSION
687 #define PRESERVE_VB_DEFS
689 #define TAG(x) intel_##x##_verts
690 #include "tnl/t_vb_rendertmp.h"
693 #define TAG(x) intel_##x##_elts
694 #define ELT(x) elt[x]
695 #include "tnl/t_vb_rendertmp.h"
697 /**********************************************************************/
698 /* Render clipped primitives */
699 /**********************************************************************/
704 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
706 struct intel_context
*intel
= intel_context(ctx
);
707 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
708 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
709 GLuint prim
= intel
->render_primitive
;
711 /* Render the new vertices as an unclipped polygon.
714 GLuint
*tmp
= VB
->Elts
;
715 VB
->Elts
= (GLuint
*) elts
;
716 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
717 PRIM_BEGIN
| PRIM_END
);
721 /* Restore the render primitive
723 if (prim
!= GL_POLYGON
)
724 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
728 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
730 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
732 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
736 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
738 struct intel_context
*intel
= intel_context(ctx
);
739 const GLuint vertsize
= intel
->vertex_size
;
740 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
741 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
742 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
745 for (i
= 2; i
< n
; i
++) {
746 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
747 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
748 COPY_DWORDS(j
, vb
, vertsize
, start
);
752 /**********************************************************************/
753 /* Choose render functions */
754 /**********************************************************************/
759 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
760 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
763 intelChooseRenderState(GLcontext
* ctx
)
765 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
766 struct intel_context
*intel
= intel_context(ctx
);
767 GLuint flags
= ctx
->_TriangleCaps
;
768 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
769 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
772 if (INTEL_DEBUG
& DEBUG_STATE
)
773 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
775 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
777 if (flags
& ANY_RASTER_FLAGS
) {
778 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
779 index
|= INTEL_TWOSIDE_BIT
;
780 if (flags
& DD_TRI_OFFSET
)
781 index
|= INTEL_OFFSET_BIT
;
782 if (flags
& DD_TRI_UNFILLED
)
783 index
|= INTEL_UNFILLED_BIT
;
787 intel
->draw_point
= intel_wpos_point
;
788 intel
->draw_line
= intel_wpos_line
;
789 intel
->draw_tri
= intel_wpos_triangle
;
791 /* Make sure these get called:
793 index
|= INTEL_FALLBACK_BIT
;
796 intel
->draw_point
= intel_draw_point
;
797 intel
->draw_line
= intel_draw_line
;
798 intel
->draw_tri
= intel_draw_triangle
;
801 /* Hook in fallbacks for specific primitives.
803 if (flags
& ANY_FALLBACK_FLAGS
) {
804 if (flags
& DD_LINE_STIPPLE
)
805 intel
->draw_line
= intel_fallback_line
;
807 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
808 intel
->draw_tri
= intel_fallback_tri
;
810 if (flags
& DD_TRI_SMOOTH
) {
811 if (intel
->strict_conformance
)
812 intel
->draw_tri
= intel_fallback_tri
;
815 if (flags
& DD_POINT_ATTEN
) {
817 intel
->draw_point
= intel_atten_point
;
819 intel
->draw_point
= intel_fallback_point
;
822 if (flags
& DD_POINT_SMOOTH
) {
823 if (intel
->strict_conformance
)
824 intel
->draw_point
= intel_fallback_point
;
827 index
|= INTEL_FALLBACK_BIT
;
831 if (intel
->RenderIndex
!= index
) {
832 intel
->RenderIndex
= index
;
834 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
835 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
836 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
837 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
840 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
841 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
842 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
843 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
846 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
847 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
848 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
849 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
854 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
868 /**********************************************************************/
869 /* High level hooks for t_vb_render.c */
870 /**********************************************************************/
876 intelRunPipeline(GLcontext
* ctx
)
878 struct intel_context
*intel
= intel_context(ctx
);
880 _mesa_lock_context_textures(ctx
);
883 _mesa_update_state_locked(ctx
);
885 if (intel
->NewGLState
) {
886 if (intel
->NewGLState
& _NEW_TEXTURE
) {
887 intel
->vtbl
.update_texture_state(intel
);
890 if (!intel
->Fallback
) {
891 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
892 intelChooseRenderState(ctx
);
895 intel
->NewGLState
= 0;
898 _tnl_run_pipeline(ctx
);
900 _mesa_unlock_context_textures(ctx
);
904 intelRenderStart(GLcontext
* ctx
)
906 struct intel_context
*intel
= intel_context(ctx
);
908 intel
->vtbl
.render_start(intel_context(ctx
));
909 intel
->vtbl
.emit_state(intel
);
913 intelRenderFinish(GLcontext
* ctx
)
915 struct intel_context
*intel
= intel_context(ctx
);
917 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
920 INTEL_FIREVERTICES(intel
);
926 /* System to flush dma and emit state changes based on the rasterized
930 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
932 struct intel_context
*intel
= intel_context(ctx
);
935 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
936 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
938 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
940 /* Start a new primitive. Arrange to have it flushed later on.
942 if (hwprim
!= intel
->prim
.primitive
) {
943 INTEL_FIREVERTICES(intel
);
945 intelStartInlinePrimitive(intel
, hwprim
, INTEL_BATCH_CLIPRECTS
);
953 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
955 struct intel_context
*intel
= intel_context(ctx
);
958 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
960 /* Let some clipping routines know which primitive they're dealing
963 intel
->render_primitive
= prim
;
965 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
966 * triangles. The rasterized primitive will always be reset by
967 * lower level functions in that case, potentially pingponging the
970 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
971 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
974 /* Set some primitive-dependent state and Start? a new primitive.
976 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
980 /**********************************************************************/
981 /* Transition to/from hardware rasterization. */
982 /**********************************************************************/
984 static char *fallbackStrings
[] = {
987 [2] = "Depth buffer",
988 [3] = "Stencil buffer",
989 [4] = "User disable",
998 [18] = "Smooth polygon",
999 [19] = "Smooth point",
1004 getFallbackString(GLuint bit
)
1011 return fallbackStrings
[i
];
1017 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1019 GLcontext
*ctx
= &intel
->ctx
;
1020 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1021 GLuint oldfallback
= intel
->Fallback
;
1024 intel
->Fallback
|= bit
;
1025 if (oldfallback
== 0) {
1027 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1028 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1029 bit
, getFallbackString(bit
));
1030 _swsetup_Wakeup(ctx
);
1031 intel
->RenderIndex
= ~0;
1035 intel
->Fallback
&= ~bit
;
1036 if (oldfallback
== bit
) {
1038 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1039 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1040 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1041 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1042 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1043 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1044 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1045 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1047 _tnl_invalidate_vertex_state(ctx
, ~0);
1048 _tnl_invalidate_vertices(ctx
, ~0);
1049 _tnl_install_attrs(ctx
,
1050 intel
->vertex_attrs
,
1051 intel
->vertex_attr_count
,
1052 intel
->ViewportMatrix
.m
, 0);
1054 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1066 /**********************************************************************/
1067 /* Used only with the metaops callbacks. */
1068 /**********************************************************************/
1070 intel_meta_draw_poly(struct intel_context
*intel
,
1073 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1077 GLboolean was_locked
= intel
->locked
;
1080 LOCK_HARDWARE(intel
);
1082 /* All 3d primitives should be emitted with INTEL_BATCH_CLIPRECTS,
1083 * otherwise the drawing origin (DR4) might not be set correctly.
1085 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, INTEL_BATCH_CLIPRECTS
);
1086 vb
= (union fi
*) intelExtendInlinePrimitive(intel
, n
* 6);
1088 for (i
= 0; i
< n
; i
++) {
1093 vb
[4].f
= tex
[i
][0];
1094 vb
[5].f
= tex
[i
][1];
1098 INTEL_FIREVERTICES(intel
);
1101 UNLOCK_HARDWARE(intel
);
1105 intel_meta_draw_quad(struct intel_context
*intel
,
1106 GLfloat x0
, GLfloat x1
,
1107 GLfloat y0
, GLfloat y1
,
1110 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1133 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1138 /**********************************************************************/
1139 /* Initialization. */
1140 /**********************************************************************/
1144 intelInitTriFuncs(GLcontext
* ctx
)
1146 struct intel_context
*intel
= intel_context(ctx
);
1147 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1148 static int firsttime
= 1;
1155 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1156 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1157 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1158 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1159 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1160 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1161 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1162 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1164 intel
->vtbl
.meta_draw_quad
= intel_meta_draw_quad
;