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 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
115 intel
->prim
.primitive
= prim
;
116 intel
->prim
.flush
= intel_flush_inline_primitive
;
121 /* _mesa_printf(">"); */
126 intelWrapInlinePrimitive(struct intel_context
*intel
)
128 GLuint prim
= intel
->prim
.primitive
;
129 GLuint batchflags
= intel
->batch
->flags
;
131 intel_flush_inline_primitive(intel
);
132 intel_batchbuffer_flush(intel
->batch
);
133 intelStartInlinePrimitive(intel
, prim
, batchflags
); /* ??? */
137 intelExtendInlinePrimitive(struct intel_context
*intel
, GLuint dwords
)
139 GLuint sz
= dwords
* sizeof(GLuint
);
142 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
144 if (intel_batchbuffer_space(intel
->batch
) < sz
)
145 intelWrapInlinePrimitive(intel
);
147 /* _mesa_printf("."); */
149 intel
->vtbl
.assert_not_dirty(intel
);
151 ptr
= (GLuint
*) intel
->batch
->ptr
;
152 intel
->batch
->ptr
+= sz
;
159 /***********************************************************************
160 * Emit primitives as inline vertices *
161 ***********************************************************************/
164 #define COPY_DWORDS( j, vb, vertsize, v ) \
167 __asm__ __volatile__( "rep ; movsl" \
168 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
174 #define COPY_DWORDS( j, vb, vertsize, v ) \
176 for ( j = 0 ; j < vertsize ; j++ ) { \
177 vb[j] = ((GLuint *)v)[j]; \
184 intel_draw_quad(struct intel_context
*intel
,
186 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
189 GLuint vertsize
= intel
->vertex_size
;
190 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 6 * vertsize
);
193 COPY_DWORDS(j
, vb
, vertsize
, v0
);
194 COPY_DWORDS(j
, vb
, vertsize
, v1
);
196 /* If smooth shading, draw like a trifan which gives better
197 * rasterization. Otherwise draw as two triangles with provoking
198 * vertex in third position as required for flat shading.
200 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
201 COPY_DWORDS(j
, vb
, vertsize
, v3
);
202 COPY_DWORDS(j
, vb
, vertsize
, v1
);
205 COPY_DWORDS(j
, vb
, vertsize
, v2
);
206 COPY_DWORDS(j
, vb
, vertsize
, v0
);
209 COPY_DWORDS(j
, vb
, vertsize
, v2
);
210 COPY_DWORDS(j
, vb
, vertsize
, v3
);
215 intel_draw_triangle(struct intel_context
*intel
,
216 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
);
231 intel_draw_line(struct intel_context
*intel
,
232 intelVertexPtr v0
, intelVertexPtr v1
)
235 GLuint vertsize
= intel
->vertex_size
;
236 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 2 * vertsize
);
239 COPY_DWORDS(j
, vb
, vertsize
, v0
);
240 COPY_DWORDS(j
, vb
, vertsize
, v1
);
246 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
249 GLuint vertsize
= intel
->vertex_size
;
250 GLuint
*vb
= intelExtendInlinePrimitive(intel
, vertsize
);
253 /* Adjust for sub pixel position -- still required for conform. */
254 *(float *) &vb
[0] = v0
->v
.x
- 0.125;
255 *(float *) &vb
[1] = v0
->v
.y
- 0.125;
256 for (j
= 2; j
< vertsize
; j
++)
263 /***********************************************************************
264 * Fixup for ARB_point_parameters *
265 ***********************************************************************/
267 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
268 * represented in the fragment program InputsRead field.
271 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
273 GLcontext
*ctx
= &intel
->ctx
;
274 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
276 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
277 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
279 restore_psz
= psz
[0];
280 restore_alpha
= col
[3];
282 if (psz
[0] >= ctx
->Point
.Threshold
) {
283 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
286 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
287 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
288 col
[3] *= dsize
* dsize
;
294 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
295 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
296 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
298 intel_draw_point(intel
, v0
);
300 psz
[0] = restore_psz
;
301 col
[3] = restore_alpha
;
303 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
304 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
307 intel_draw_point(intel
, v0
);
314 /***********************************************************************
315 * Fixup for I915 WPOS texture coordinate *
316 ***********************************************************************/
321 intel_wpos_triangle(struct intel_context
*intel
,
322 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
324 GLuint offset
= intel
->wpos_offset
;
325 GLuint size
= intel
->wpos_size
;
327 __memcpy(((char *) v0
) + offset
, v0
, size
);
328 __memcpy(((char *) v1
) + offset
, v1
, size
);
329 __memcpy(((char *) v2
) + offset
, v2
, size
);
331 intel_draw_triangle(intel
, v0
, v1
, v2
);
336 intel_wpos_line(struct intel_context
*intel
,
337 intelVertexPtr v0
, intelVertexPtr v1
)
339 GLuint offset
= intel
->wpos_offset
;
340 GLuint size
= intel
->wpos_size
;
342 __memcpy(((char *) v0
) + offset
, v0
, size
);
343 __memcpy(((char *) v1
) + offset
, v1
, size
);
345 intel_draw_line(intel
, v0
, v1
);
350 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
352 GLuint offset
= intel
->wpos_offset
;
353 GLuint size
= intel
->wpos_size
;
355 __memcpy(((char *) v0
) + offset
, v0
, size
);
357 intel_draw_point(intel
, v0
);
365 /***********************************************************************
366 * Macros for t_dd_tritmp.h to draw basic primitives *
367 ***********************************************************************/
369 #define TRI( a, b, c ) \
372 intel->draw_tri( intel, a, b, c ); \
374 intel_draw_triangle( intel, a, b, c ); \
377 #define QUAD( a, b, c, d ) \
380 intel->draw_tri( intel, a, b, d ); \
381 intel->draw_tri( intel, b, c, d ); \
383 intel_draw_quad( intel, a, b, c, d ); \
386 #define LINE( v0, v1 ) \
389 intel->draw_line( intel, v0, v1 ); \
391 intel_draw_line( intel, v0, v1 ); \
394 #define POINT( v0 ) \
397 intel->draw_point( intel, v0 ); \
399 intel_draw_point( intel, v0 ); \
403 /***********************************************************************
404 * Build render functions from dd templates *
405 ***********************************************************************/
407 #define INTEL_OFFSET_BIT 0x01
408 #define INTEL_TWOSIDE_BIT 0x02
409 #define INTEL_UNFILLED_BIT 0x04
410 #define INTEL_FALLBACK_BIT 0x08
411 #define INTEL_MAX_TRIFUNC 0x10
416 tnl_points_func points
;
418 tnl_triangle_func triangle
;
420 } rast_tab
[INTEL_MAX_TRIFUNC
];
423 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
424 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
425 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
426 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
432 #define DO_FULL_QUAD 1
436 #define HAVE_BACK_COLORS 0
437 #define HAVE_HW_FLATSHADE 1
438 #define VERTEX intelVertex
441 /* Only used to pull back colors into vertices (ie, we know color is
444 #define INTEL_COLOR( dst, src ) \
446 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
447 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
448 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
449 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
452 #define INTEL_SPEC( dst, src ) \
454 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
455 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
456 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
460 #define DEPTH_SCALE intel->polygon_offset_scale
461 #define UNFILLED_TRI unfilled_tri
462 #define UNFILLED_QUAD unfilled_quad
463 #define VERT_X(_v) _v->v.x
464 #define VERT_Y(_v) _v->v.y
465 #define VERT_Z(_v) _v->v.z
466 #define AREA_IS_CCW( a ) (a > 0)
467 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
469 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
470 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
471 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
472 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
474 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
475 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
476 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
477 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
479 #define LOCAL_VARS(n) \
480 struct intel_context *intel = intel_context(ctx); \
481 GLuint color[n], spec[n]; \
482 GLuint coloroffset = intel->coloroffset; \
483 GLboolean specoffset = intel->specoffset; \
484 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
487 /***********************************************************************
488 * Helpers for rendering unfilled primitives *
489 ***********************************************************************/
491 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
504 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
505 #define RENDER_PRIMITIVE intel->render_primitive
507 #define IND INTEL_FALLBACK_BIT
508 #include "tnl_dd/t_dd_unfilled.h"
511 /***********************************************************************
512 * Generate GL render functions *
513 ***********************************************************************/
517 #include "tnl_dd/t_dd_tritmp.h"
519 #define IND (INTEL_OFFSET_BIT)
520 #define TAG(x) x##_offset
521 #include "tnl_dd/t_dd_tritmp.h"
523 #define IND (INTEL_TWOSIDE_BIT)
524 #define TAG(x) x##_twoside
525 #include "tnl_dd/t_dd_tritmp.h"
527 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
528 #define TAG(x) x##_twoside_offset
529 #include "tnl_dd/t_dd_tritmp.h"
531 #define IND (INTEL_UNFILLED_BIT)
532 #define TAG(x) x##_unfilled
533 #include "tnl_dd/t_dd_tritmp.h"
535 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
536 #define TAG(x) x##_offset_unfilled
537 #include "tnl_dd/t_dd_tritmp.h"
539 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
540 #define TAG(x) x##_twoside_unfilled
541 #include "tnl_dd/t_dd_tritmp.h"
543 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
544 #define TAG(x) x##_twoside_offset_unfilled
545 #include "tnl_dd/t_dd_tritmp.h"
547 #define IND (INTEL_FALLBACK_BIT)
548 #define TAG(x) x##_fallback
549 #include "tnl_dd/t_dd_tritmp.h"
551 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
552 #define TAG(x) x##_offset_fallback
553 #include "tnl_dd/t_dd_tritmp.h"
555 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
556 #define TAG(x) x##_twoside_fallback
557 #include "tnl_dd/t_dd_tritmp.h"
559 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
560 #define TAG(x) x##_twoside_offset_fallback
561 #include "tnl_dd/t_dd_tritmp.h"
563 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
564 #define TAG(x) x##_unfilled_fallback
565 #include "tnl_dd/t_dd_tritmp.h"
567 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
568 #define TAG(x) x##_offset_unfilled_fallback
569 #include "tnl_dd/t_dd_tritmp.h"
571 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
572 #define TAG(x) x##_twoside_unfilled_fallback
573 #include "tnl_dd/t_dd_tritmp.h"
575 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
577 #define TAG(x) x##_twoside_offset_unfilled_fallback
578 #include "tnl_dd/t_dd_tritmp.h"
587 init_twoside_offset();
589 init_offset_unfilled();
590 init_twoside_unfilled();
591 init_twoside_offset_unfilled();
593 init_offset_fallback();
594 init_twoside_fallback();
595 init_twoside_offset_fallback();
596 init_unfilled_fallback();
597 init_offset_unfilled_fallback();
598 init_twoside_unfilled_fallback();
599 init_twoside_offset_unfilled_fallback();
603 /***********************************************************************
604 * Rasterization fallback helpers *
605 ***********************************************************************/
608 /* This code is hit only when a mix of accelerated and unaccelerated
609 * primitives are being drawn, and only for the unaccelerated
613 intel_fallback_tri(struct intel_context
*intel
,
614 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
616 GLcontext
*ctx
= &intel
->ctx
;
620 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
622 INTEL_FIREVERTICES(intel
);
624 _swsetup_Translate(ctx
, v0
, &v
[0]);
625 _swsetup_Translate(ctx
, v1
, &v
[1]);
626 _swsetup_Translate(ctx
, v2
, &v
[2]);
627 intelSpanRenderStart(ctx
);
628 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
629 intelSpanRenderFinish(ctx
);
634 intel_fallback_line(struct intel_context
*intel
,
635 intelVertex
* v0
, intelVertex
* v1
)
637 GLcontext
*ctx
= &intel
->ctx
;
641 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
643 INTEL_FIREVERTICES(intel
);
645 _swsetup_Translate(ctx
, v0
, &v
[0]);
646 _swsetup_Translate(ctx
, v1
, &v
[1]);
647 intelSpanRenderStart(ctx
);
648 _swrast_Line(ctx
, &v
[0], &v
[1]);
649 intelSpanRenderFinish(ctx
);
653 intel_fallback_point(struct intel_context
*intel
,
656 GLcontext
*ctx
= &intel
->ctx
;
660 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
662 INTEL_FIREVERTICES(intel
);
664 _swsetup_Translate(ctx
, v0
, &v
[0]);
665 intelSpanRenderStart(ctx
);
666 _swrast_Point(ctx
, &v
[0]);
667 intelSpanRenderFinish(ctx
);
671 /**********************************************************************/
672 /* Render unclipped begin/end objects */
673 /**********************************************************************/
676 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
677 #define RENDER_POINTS( start, count ) \
678 for ( ; start < count ; start++) POINT( V(ELT(start)) );
679 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
680 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
681 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
682 #define INIT(x) intelRenderPrimitive( ctx, x )
685 struct intel_context *intel = intel_context(ctx); \
686 GLubyte *vertptr = (GLubyte *)intel->verts; \
687 const GLuint vertsize = intel->vertex_size; \
688 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
690 #define RESET_STIPPLE
691 #define RESET_OCCLUSION
692 #define PRESERVE_VB_DEFS
694 #define TAG(x) intel_##x##_verts
695 #include "tnl/t_vb_rendertmp.h"
698 #define TAG(x) intel_##x##_elts
699 #define ELT(x) elt[x]
700 #include "tnl/t_vb_rendertmp.h"
702 /**********************************************************************/
703 /* Render clipped primitives */
704 /**********************************************************************/
709 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
711 struct intel_context
*intel
= intel_context(ctx
);
712 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
713 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
714 GLuint prim
= intel
->render_primitive
;
716 /* Render the new vertices as an unclipped polygon.
719 GLuint
*tmp
= VB
->Elts
;
720 VB
->Elts
= (GLuint
*) elts
;
721 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
722 PRIM_BEGIN
| PRIM_END
);
726 /* Restore the render primitive
728 if (prim
!= GL_POLYGON
)
729 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
733 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
735 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
737 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
741 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
744 struct intel_context
*intel
= intel_context(ctx
);
745 const GLuint vertsize
= intel
->vertex_size
;
746 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
747 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
748 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
751 for (i
= 2; i
< n
; i
++) {
752 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
753 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
754 COPY_DWORDS(j
, vb
, vertsize
, start
);
759 /**********************************************************************/
760 /* Choose render functions */
761 /**********************************************************************/
766 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
767 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
770 intelChooseRenderState(GLcontext
* ctx
)
772 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
773 struct intel_context
*intel
= intel_context(ctx
);
774 GLuint flags
= ctx
->_TriangleCaps
;
775 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
776 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
779 if (INTEL_DEBUG
& DEBUG_STATE
)
780 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
782 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
784 if (flags
& ANY_RASTER_FLAGS
) {
785 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
786 index
|= INTEL_TWOSIDE_BIT
;
787 if (flags
& DD_TRI_OFFSET
)
788 index
|= INTEL_OFFSET_BIT
;
789 if (flags
& DD_TRI_UNFILLED
)
790 index
|= INTEL_UNFILLED_BIT
;
794 intel
->draw_point
= intel_wpos_point
;
795 intel
->draw_line
= intel_wpos_line
;
796 intel
->draw_tri
= intel_wpos_triangle
;
798 /* Make sure these get called:
800 index
|= INTEL_FALLBACK_BIT
;
803 intel
->draw_point
= intel_draw_point
;
804 intel
->draw_line
= intel_draw_line
;
805 intel
->draw_tri
= intel_draw_triangle
;
808 /* Hook in fallbacks for specific primitives.
810 if (flags
& ANY_FALLBACK_FLAGS
) {
811 if (flags
& DD_LINE_STIPPLE
)
812 intel
->draw_line
= intel_fallback_line
;
814 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
815 intel
->draw_tri
= intel_fallback_tri
;
817 if (flags
& DD_TRI_SMOOTH
) {
818 if (intel
->strict_conformance
)
819 intel
->draw_tri
= intel_fallback_tri
;
822 if (flags
& DD_POINT_ATTEN
) {
824 intel
->draw_point
= intel_atten_point
;
826 intel
->draw_point
= intel_fallback_point
;
829 if (flags
& DD_POINT_SMOOTH
) {
830 if (intel
->strict_conformance
)
831 intel
->draw_point
= intel_fallback_point
;
834 index
|= INTEL_FALLBACK_BIT
;
838 if (intel
->RenderIndex
!= index
) {
839 intel
->RenderIndex
= index
;
841 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
842 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
843 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
844 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
847 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
848 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
849 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
850 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
853 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
854 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
855 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
856 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
861 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
875 /**********************************************************************/
876 /* High level hooks for t_vb_render.c */
877 /**********************************************************************/
883 intelRunPipeline(GLcontext
* ctx
)
885 struct intel_context
*intel
= intel_context(ctx
);
887 _mesa_lock_context_textures(ctx
);
890 _mesa_update_state_locked(ctx
);
892 if (intel
->NewGLState
) {
893 if (intel
->NewGLState
& _NEW_TEXTURE
) {
894 intel
->vtbl
.update_texture_state(intel
);
897 if (!intel
->Fallback
) {
898 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
899 intelChooseRenderState(ctx
);
902 intel
->NewGLState
= 0;
905 _tnl_run_pipeline(ctx
);
907 _mesa_unlock_context_textures(ctx
);
911 intelRenderStart(GLcontext
* ctx
)
913 struct intel_context
*intel
= intel_context(ctx
);
915 intel
->vtbl
.render_start(intel_context(ctx
));
916 intel
->vtbl
.emit_state(intel
);
920 intelRenderFinish(GLcontext
* ctx
)
922 struct intel_context
*intel
= intel_context(ctx
);
924 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
927 INTEL_FIREVERTICES(intel
);
933 /* System to flush dma and emit state changes based on the rasterized
937 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
939 struct intel_context
*intel
= intel_context(ctx
);
942 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
943 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
945 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
947 /* Start a new primitive. Arrange to have it flushed later on.
949 if (hwprim
!= intel
->prim
.primitive
) {
950 INTEL_FIREVERTICES(intel
);
952 intelStartInlinePrimitive(intel
, hwprim
, INTEL_BATCH_CLIPRECTS
);
960 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
962 struct intel_context
*intel
= intel_context(ctx
);
965 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
967 /* Let some clipping routines know which primitive they're dealing
970 intel
->render_primitive
= prim
;
972 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
973 * triangles. The rasterized primitive will always be reset by
974 * lower level functions in that case, potentially pingponging the
977 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
978 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
981 /* Set some primitive-dependent state and Start? a new primitive.
983 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
987 /**********************************************************************/
988 /* Transition to/from hardware rasterization. */
989 /**********************************************************************/
991 static char *fallbackStrings
[] = {
994 [2] = "Depth buffer",
995 [3] = "Stencil buffer",
996 [4] = "User disable",
1000 [13] = "Color mask",
1005 [18] = "Smooth polygon",
1006 [19] = "Smooth point",
1011 getFallbackString(GLuint bit
)
1018 return fallbackStrings
[i
];
1024 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1026 GLcontext
*ctx
= &intel
->ctx
;
1027 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1028 GLuint oldfallback
= intel
->Fallback
;
1031 intel
->Fallback
|= bit
;
1032 if (oldfallback
== 0) {
1034 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1035 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1036 bit
, getFallbackString(bit
));
1037 _swsetup_Wakeup(ctx
);
1038 intel
->RenderIndex
= ~0;
1042 intel
->Fallback
&= ~bit
;
1043 if (oldfallback
== bit
) {
1045 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1046 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1047 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1048 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1049 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1050 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1051 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1052 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1054 _tnl_invalidate_vertex_state(ctx
, ~0);
1055 _tnl_invalidate_vertices(ctx
, ~0);
1056 _tnl_install_attrs(ctx
,
1057 intel
->vertex_attrs
,
1058 intel
->vertex_attr_count
,
1059 intel
->ViewportMatrix
.m
, 0);
1061 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1073 /**********************************************************************/
1074 /* Used only with the metaops callbacks. */
1075 /**********************************************************************/
1077 intel_meta_draw_poly(struct intel_context
*intel
,
1080 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1086 /* All 3d primitives should be emitted with INTEL_BATCH_CLIPRECTS,
1087 * otherwise the drawing origin (DR4) might not be set correctly.
1089 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, INTEL_BATCH_CLIPRECTS
);
1090 vb
= (union fi
*) intelExtendInlinePrimitive(intel
, n
* 6);
1092 for (i
= 0; i
< n
; i
++) {
1097 vb
[4].f
= tex
[i
][0];
1098 vb
[5].f
= tex
[i
][1];
1102 INTEL_FIREVERTICES(intel
);
1107 intel_meta_draw_quad(struct intel_context
*intel
,
1108 GLfloat x0
, GLfloat x1
,
1109 GLfloat y0
, GLfloat y1
,
1112 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1135 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1140 /**********************************************************************/
1141 /* Initialization. */
1142 /**********************************************************************/
1146 intelInitTriFuncs(GLcontext
* ctx
)
1148 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1149 static int firsttime
= 1;
1156 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1157 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1158 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1159 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1160 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1161 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1162 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1163 tnl
->Driver
.Render
.Interp
= _tnl_interp
;