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_reg.h"
47 #include "intel_span.h"
48 #include "intel_tex.h"
50 static void intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
);
51 static void intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
,
57 intel_flush_inline_primitive(struct intel_context
*intel
)
59 GLuint used
= intel
->batch
->ptr
- intel
->prim
.start_ptr
;
61 assert(intel
->prim
.primitive
!= ~0);
63 /* _mesa_printf("/\n"); */
68 *(int *) intel
->prim
.start_ptr
= (_3DPRIMITIVE
|
69 intel
->prim
.primitive
| (used
/ 4 - 2));
74 intel
->batch
->ptr
-= used
;
77 intel
->prim
.primitive
= ~0;
78 intel
->prim
.start_ptr
= 0;
79 intel
->prim
.flush
= 0;
83 /* Emit a primitive referencing vertices in a vertex buffer.
86 intelStartInlinePrimitive(struct intel_context
*intel
,
87 GLuint prim
, GLuint batch_flags
)
91 intel
->vtbl
.emit_state(intel
);
93 /* Need to make sure at the very least that we don't wrap
94 * batchbuffers in BEGIN_BATCH below, otherwise the primitive will
95 * be emitted to a batchbuffer missing the required full-state
98 if (intel_batchbuffer_space(intel
->batch
) < 100) {
99 intel_batchbuffer_flush(intel
->batch
);
100 intel
->vtbl
.emit_state(intel
);
103 /* _mesa_printf("%s *", __progname); */
105 /* Emit a slot which will be filled with the inline primitive
108 BEGIN_BATCH(2, batch_flags
);
111 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
112 intel
->prim
.primitive
= prim
;
113 intel
->prim
.flush
= intel_flush_inline_primitive
;
118 /* _mesa_printf(">"); */
123 intelWrapInlinePrimitive(struct intel_context
*intel
)
125 GLuint prim
= intel
->prim
.primitive
;
126 GLuint batchflags
= intel
->batch
->flags
;
128 intel_flush_inline_primitive(intel
);
129 intel_batchbuffer_flush(intel
->batch
);
130 intelStartInlinePrimitive(intel
, prim
, batchflags
); /* ??? */
134 intelExtendInlinePrimitive(struct intel_context
*intel
, GLuint dwords
)
136 GLuint sz
= dwords
* sizeof(GLuint
);
139 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
141 if (intel_batchbuffer_space(intel
->batch
) < sz
)
142 intelWrapInlinePrimitive(intel
);
144 /* _mesa_printf("."); */
146 intel
->vtbl
.assert_not_dirty(intel
);
148 ptr
= (GLuint
*) intel
->batch
->ptr
;
149 intel
->batch
->ptr
+= sz
;
156 /***********************************************************************
157 * Emit primitives as inline vertices *
158 ***********************************************************************/
161 #define COPY_DWORDS( j, vb, vertsize, v ) \
164 __asm__ __volatile__( "rep ; movsl" \
165 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
171 #define COPY_DWORDS( j, vb, vertsize, v ) \
173 for ( j = 0 ; j < vertsize ; j++ ) { \
174 vb[j] = ((GLuint *)v)[j]; \
181 intel_draw_quad(struct intel_context
*intel
,
183 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
185 GLuint vertsize
= intel
->vertex_size
;
186 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 6 * vertsize
);
189 COPY_DWORDS(j
, vb
, vertsize
, v0
);
190 COPY_DWORDS(j
, vb
, vertsize
, v1
);
192 /* If smooth shading, draw like a trifan which gives better
193 * rasterization. Otherwise draw as two triangles with provoking
194 * vertex in third position as required for flat shading.
196 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
197 COPY_DWORDS(j
, vb
, vertsize
, v3
);
198 COPY_DWORDS(j
, vb
, vertsize
, v1
);
201 COPY_DWORDS(j
, vb
, vertsize
, v2
);
202 COPY_DWORDS(j
, vb
, vertsize
, v0
);
205 COPY_DWORDS(j
, vb
, vertsize
, v2
);
206 COPY_DWORDS(j
, vb
, vertsize
, v3
);
210 intel_draw_triangle(struct intel_context
*intel
,
211 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
213 GLuint vertsize
= intel
->vertex_size
;
214 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 3 * vertsize
);
217 COPY_DWORDS(j
, vb
, vertsize
, v0
);
218 COPY_DWORDS(j
, vb
, vertsize
, v1
);
219 COPY_DWORDS(j
, vb
, vertsize
, v2
);
224 intel_draw_line(struct intel_context
*intel
,
225 intelVertexPtr v0
, intelVertexPtr v1
)
227 GLuint vertsize
= intel
->vertex_size
;
228 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 2 * vertsize
);
231 COPY_DWORDS(j
, vb
, vertsize
, v0
);
232 COPY_DWORDS(j
, vb
, vertsize
, v1
);
237 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
239 GLuint vertsize
= intel
->vertex_size
;
240 GLuint
*vb
= intelExtendInlinePrimitive(intel
, vertsize
);
243 /* Adjust for sub pixel position -- still required for conform. */
244 *(float *) &vb
[0] = v0
->v
.x
- 0.125;
245 *(float *) &vb
[1] = v0
->v
.y
- 0.125;
246 for (j
= 2; j
< vertsize
; j
++)
252 /***********************************************************************
253 * Fixup for ARB_point_parameters *
254 ***********************************************************************/
256 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
257 * represented in the fragment program InputsRead field.
260 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
262 GLcontext
*ctx
= &intel
->ctx
;
263 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
265 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
266 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
268 restore_psz
= psz
[0];
269 restore_alpha
= col
[3];
271 if (psz
[0] >= ctx
->Point
.Threshold
) {
272 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
275 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
276 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
277 col
[3] *= dsize
* dsize
;
283 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
284 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
285 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
287 intel_draw_point(intel
, v0
);
289 psz
[0] = restore_psz
;
290 col
[3] = restore_alpha
;
292 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
293 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
296 intel_draw_point(intel
, v0
);
303 /***********************************************************************
304 * Fixup for I915 WPOS texture coordinate *
305 ***********************************************************************/
310 intel_wpos_triangle(struct intel_context
*intel
,
311 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
313 GLuint offset
= intel
->wpos_offset
;
314 GLuint size
= intel
->wpos_size
;
316 __memcpy(((char *) v0
) + offset
, v0
, size
);
317 __memcpy(((char *) v1
) + offset
, v1
, size
);
318 __memcpy(((char *) v2
) + offset
, v2
, size
);
320 intel_draw_triangle(intel
, v0
, v1
, v2
);
325 intel_wpos_line(struct intel_context
*intel
,
326 intelVertexPtr v0
, intelVertexPtr v1
)
328 GLuint offset
= intel
->wpos_offset
;
329 GLuint size
= intel
->wpos_size
;
331 __memcpy(((char *) v0
) + offset
, v0
, size
);
332 __memcpy(((char *) v1
) + offset
, v1
, size
);
334 intel_draw_line(intel
, v0
, v1
);
339 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
341 GLuint offset
= intel
->wpos_offset
;
342 GLuint size
= intel
->wpos_size
;
344 __memcpy(((char *) v0
) + offset
, v0
, size
);
346 intel_draw_point(intel
, v0
);
354 /***********************************************************************
355 * Macros for t_dd_tritmp.h to draw basic primitives *
356 ***********************************************************************/
358 #define TRI( a, b, c ) \
361 intel->draw_tri( intel, a, b, c ); \
363 intel_draw_triangle( intel, a, b, c ); \
366 #define QUAD( a, b, c, d ) \
369 intel->draw_tri( intel, a, b, d ); \
370 intel->draw_tri( intel, b, c, d ); \
372 intel_draw_quad( intel, a, b, c, d ); \
375 #define LINE( v0, v1 ) \
378 intel->draw_line( intel, v0, v1 ); \
380 intel_draw_line( intel, v0, v1 ); \
383 #define POINT( v0 ) \
386 intel->draw_point( intel, v0 ); \
388 intel_draw_point( intel, v0 ); \
392 /***********************************************************************
393 * Build render functions from dd templates *
394 ***********************************************************************/
396 #define INTEL_OFFSET_BIT 0x01
397 #define INTEL_TWOSIDE_BIT 0x02
398 #define INTEL_UNFILLED_BIT 0x04
399 #define INTEL_FALLBACK_BIT 0x08
400 #define INTEL_MAX_TRIFUNC 0x10
405 tnl_points_func points
;
407 tnl_triangle_func triangle
;
409 } rast_tab
[INTEL_MAX_TRIFUNC
];
412 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
413 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
414 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
415 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
421 #define DO_FULL_QUAD 1
425 #define HAVE_BACK_COLORS 0
426 #define HAVE_HW_FLATSHADE 1
427 #define VERTEX intelVertex
430 /* Only used to pull back colors into vertices (ie, we know color is
433 #define INTEL_COLOR( dst, src ) \
435 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
436 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
437 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
438 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
441 #define INTEL_SPEC( dst, src ) \
443 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
444 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
445 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
449 #define DEPTH_SCALE intel->polygon_offset_scale
450 #define UNFILLED_TRI unfilled_tri
451 #define UNFILLED_QUAD unfilled_quad
452 #define VERT_X(_v) _v->v.x
453 #define VERT_Y(_v) _v->v.y
454 #define VERT_Z(_v) _v->v.z
455 #define AREA_IS_CCW( a ) (a > 0)
456 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
458 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
459 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
460 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
461 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
463 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
464 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
465 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
466 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
468 #define LOCAL_VARS(n) \
469 struct intel_context *intel = intel_context(ctx); \
470 GLuint color[n], spec[n]; \
471 GLuint coloroffset = intel->coloroffset; \
472 GLboolean specoffset = intel->specoffset; \
473 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
476 /***********************************************************************
477 * Helpers for rendering unfilled primitives *
478 ***********************************************************************/
480 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
493 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
494 #define RENDER_PRIMITIVE intel->render_primitive
496 #define IND INTEL_FALLBACK_BIT
497 #include "tnl_dd/t_dd_unfilled.h"
500 /***********************************************************************
501 * Generate GL render functions *
502 ***********************************************************************/
506 #include "tnl_dd/t_dd_tritmp.h"
508 #define IND (INTEL_OFFSET_BIT)
509 #define TAG(x) x##_offset
510 #include "tnl_dd/t_dd_tritmp.h"
512 #define IND (INTEL_TWOSIDE_BIT)
513 #define TAG(x) x##_twoside
514 #include "tnl_dd/t_dd_tritmp.h"
516 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
517 #define TAG(x) x##_twoside_offset
518 #include "tnl_dd/t_dd_tritmp.h"
520 #define IND (INTEL_UNFILLED_BIT)
521 #define TAG(x) x##_unfilled
522 #include "tnl_dd/t_dd_tritmp.h"
524 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
525 #define TAG(x) x##_offset_unfilled
526 #include "tnl_dd/t_dd_tritmp.h"
528 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
529 #define TAG(x) x##_twoside_unfilled
530 #include "tnl_dd/t_dd_tritmp.h"
532 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
533 #define TAG(x) x##_twoside_offset_unfilled
534 #include "tnl_dd/t_dd_tritmp.h"
536 #define IND (INTEL_FALLBACK_BIT)
537 #define TAG(x) x##_fallback
538 #include "tnl_dd/t_dd_tritmp.h"
540 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
541 #define TAG(x) x##_offset_fallback
542 #include "tnl_dd/t_dd_tritmp.h"
544 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
545 #define TAG(x) x##_twoside_fallback
546 #include "tnl_dd/t_dd_tritmp.h"
548 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
549 #define TAG(x) x##_twoside_offset_fallback
550 #include "tnl_dd/t_dd_tritmp.h"
552 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
553 #define TAG(x) x##_unfilled_fallback
554 #include "tnl_dd/t_dd_tritmp.h"
556 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
557 #define TAG(x) x##_offset_unfilled_fallback
558 #include "tnl_dd/t_dd_tritmp.h"
560 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
561 #define TAG(x) x##_twoside_unfilled_fallback
562 #include "tnl_dd/t_dd_tritmp.h"
564 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
566 #define TAG(x) x##_twoside_offset_unfilled_fallback
567 #include "tnl_dd/t_dd_tritmp.h"
576 init_twoside_offset();
578 init_offset_unfilled();
579 init_twoside_unfilled();
580 init_twoside_offset_unfilled();
582 init_offset_fallback();
583 init_twoside_fallback();
584 init_twoside_offset_fallback();
585 init_unfilled_fallback();
586 init_offset_unfilled_fallback();
587 init_twoside_unfilled_fallback();
588 init_twoside_offset_unfilled_fallback();
592 /***********************************************************************
593 * Rasterization fallback helpers *
594 ***********************************************************************/
597 /* This code is hit only when a mix of accelerated and unaccelerated
598 * primitives are being drawn, and only for the unaccelerated
602 intel_fallback_tri(struct intel_context
*intel
,
603 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
605 GLcontext
*ctx
= &intel
->ctx
;
609 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
611 INTEL_FIREVERTICES(intel
);
613 _swsetup_Translate(ctx
, v0
, &v
[0]);
614 _swsetup_Translate(ctx
, v1
, &v
[1]);
615 _swsetup_Translate(ctx
, v2
, &v
[2]);
616 intelSpanRenderStart(ctx
);
617 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
618 intelSpanRenderFinish(ctx
);
623 intel_fallback_line(struct intel_context
*intel
,
624 intelVertex
* v0
, intelVertex
* v1
)
626 GLcontext
*ctx
= &intel
->ctx
;
630 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
632 INTEL_FIREVERTICES(intel
);
634 _swsetup_Translate(ctx
, v0
, &v
[0]);
635 _swsetup_Translate(ctx
, v1
, &v
[1]);
636 intelSpanRenderStart(ctx
);
637 _swrast_Line(ctx
, &v
[0], &v
[1]);
638 intelSpanRenderFinish(ctx
);
642 intel_fallback_point(struct intel_context
*intel
,
645 GLcontext
*ctx
= &intel
->ctx
;
649 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
651 INTEL_FIREVERTICES(intel
);
653 _swsetup_Translate(ctx
, v0
, &v
[0]);
654 intelSpanRenderStart(ctx
);
655 _swrast_Point(ctx
, &v
[0]);
656 intelSpanRenderFinish(ctx
);
660 /**********************************************************************/
661 /* Render unclipped begin/end objects */
662 /**********************************************************************/
665 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
666 #define RENDER_POINTS( start, count ) \
667 for ( ; start < count ; start++) POINT( V(ELT(start)) );
668 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
669 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
670 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
671 #define INIT(x) intelRenderPrimitive( ctx, x )
674 struct intel_context *intel = intel_context(ctx); \
675 GLubyte *vertptr = (GLubyte *)intel->verts; \
676 const GLuint vertsize = intel->vertex_size; \
677 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
679 #define RESET_STIPPLE
680 #define RESET_OCCLUSION
681 #define PRESERVE_VB_DEFS
683 #define TAG(x) intel_##x##_verts
684 #include "tnl/t_vb_rendertmp.h"
687 #define TAG(x) intel_##x##_elts
688 #define ELT(x) elt[x]
689 #include "tnl/t_vb_rendertmp.h"
691 /**********************************************************************/
692 /* Render clipped primitives */
693 /**********************************************************************/
698 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
700 struct intel_context
*intel
= intel_context(ctx
);
701 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
702 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
703 GLuint prim
= intel
->render_primitive
;
705 /* Render the new vertices as an unclipped polygon.
708 GLuint
*tmp
= VB
->Elts
;
709 VB
->Elts
= (GLuint
*) elts
;
710 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
711 PRIM_BEGIN
| PRIM_END
);
715 /* Restore the render primitive
717 if (prim
!= GL_POLYGON
)
718 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
722 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
724 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
726 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
730 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
732 struct intel_context
*intel
= intel_context(ctx
);
733 const GLuint vertsize
= intel
->vertex_size
;
734 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
735 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
736 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
739 for (i
= 2; i
< n
; i
++) {
740 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
741 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
742 COPY_DWORDS(j
, vb
, vertsize
, start
);
746 /**********************************************************************/
747 /* Choose render functions */
748 /**********************************************************************/
753 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
754 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
757 intelChooseRenderState(GLcontext
* ctx
)
759 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
760 struct intel_context
*intel
= intel_context(ctx
);
761 GLuint flags
= ctx
->_TriangleCaps
;
762 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
763 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
766 if (INTEL_DEBUG
& DEBUG_STATE
)
767 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
769 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
771 if (flags
& ANY_RASTER_FLAGS
) {
772 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
773 index
|= INTEL_TWOSIDE_BIT
;
774 if (flags
& DD_TRI_OFFSET
)
775 index
|= INTEL_OFFSET_BIT
;
776 if (flags
& DD_TRI_UNFILLED
)
777 index
|= INTEL_UNFILLED_BIT
;
781 intel
->draw_point
= intel_wpos_point
;
782 intel
->draw_line
= intel_wpos_line
;
783 intel
->draw_tri
= intel_wpos_triangle
;
785 /* Make sure these get called:
787 index
|= INTEL_FALLBACK_BIT
;
790 intel
->draw_point
= intel_draw_point
;
791 intel
->draw_line
= intel_draw_line
;
792 intel
->draw_tri
= intel_draw_triangle
;
795 /* Hook in fallbacks for specific primitives.
797 if (flags
& ANY_FALLBACK_FLAGS
) {
798 if (flags
& DD_LINE_STIPPLE
)
799 intel
->draw_line
= intel_fallback_line
;
801 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
802 intel
->draw_tri
= intel_fallback_tri
;
804 if (flags
& DD_TRI_SMOOTH
) {
805 if (intel
->strict_conformance
)
806 intel
->draw_tri
= intel_fallback_tri
;
809 if (flags
& DD_POINT_ATTEN
) {
811 intel
->draw_point
= intel_atten_point
;
813 intel
->draw_point
= intel_fallback_point
;
816 if (flags
& DD_POINT_SMOOTH
) {
817 if (intel
->strict_conformance
)
818 intel
->draw_point
= intel_fallback_point
;
821 index
|= INTEL_FALLBACK_BIT
;
825 if (intel
->RenderIndex
!= index
) {
826 intel
->RenderIndex
= index
;
828 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
829 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
830 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
831 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
834 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
835 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
836 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
837 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
840 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
841 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
842 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
843 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
848 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
862 /**********************************************************************/
863 /* High level hooks for t_vb_render.c */
864 /**********************************************************************/
870 intelRunPipeline(GLcontext
* ctx
)
872 struct intel_context
*intel
= intel_context(ctx
);
874 _mesa_lock_context_textures(ctx
);
877 _mesa_update_state_locked(ctx
);
879 if (intel
->NewGLState
) {
880 if (intel
->NewGLState
& _NEW_TEXTURE
) {
881 intel
->vtbl
.update_texture_state(intel
);
884 if (!intel
->Fallback
) {
885 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
886 intelChooseRenderState(ctx
);
889 intel
->NewGLState
= 0;
892 _tnl_run_pipeline(ctx
);
894 _mesa_unlock_context_textures(ctx
);
898 intelRenderStart(GLcontext
* ctx
)
900 struct intel_context
*intel
= intel_context(ctx
);
902 intel
->vtbl
.render_start(intel_context(ctx
));
903 intel
->vtbl
.emit_state(intel
);
907 intelRenderFinish(GLcontext
* ctx
)
909 struct intel_context
*intel
= intel_context(ctx
);
911 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
914 INTEL_FIREVERTICES(intel
);
920 /* System to flush dma and emit state changes based on the rasterized
924 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
926 struct intel_context
*intel
= intel_context(ctx
);
929 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
930 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
932 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
934 /* Start a new primitive. Arrange to have it flushed later on.
936 if (hwprim
!= intel
->prim
.primitive
) {
937 INTEL_FIREVERTICES(intel
);
939 intelStartInlinePrimitive(intel
, hwprim
, INTEL_BATCH_CLIPRECTS
);
947 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
949 struct intel_context
*intel
= intel_context(ctx
);
952 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
954 /* Let some clipping routines know which primitive they're dealing
957 intel
->render_primitive
= prim
;
959 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
960 * triangles. The rasterized primitive will always be reset by
961 * lower level functions in that case, potentially pingponging the
964 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
965 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
968 /* Set some primitive-dependent state and Start? a new primitive.
970 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
974 /**********************************************************************/
975 /* Transition to/from hardware rasterization. */
976 /**********************************************************************/
978 static char *fallbackStrings
[] = {
981 [2] = "Depth buffer",
982 [3] = "Stencil buffer",
983 [4] = "User disable",
992 [18] = "Smooth polygon",
993 [19] = "Smooth point",
998 getFallbackString(GLuint bit
)
1005 return fallbackStrings
[i
];
1011 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1013 GLcontext
*ctx
= &intel
->ctx
;
1014 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1015 GLuint oldfallback
= intel
->Fallback
;
1018 intel
->Fallback
|= bit
;
1019 if (oldfallback
== 0) {
1021 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1022 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1023 bit
, getFallbackString(bit
));
1024 _swsetup_Wakeup(ctx
);
1025 intel
->RenderIndex
= ~0;
1029 intel
->Fallback
&= ~bit
;
1030 if (oldfallback
== bit
) {
1032 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1033 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1034 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1035 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1036 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1037 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1038 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1039 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1041 _tnl_invalidate_vertex_state(ctx
, ~0);
1042 _tnl_invalidate_vertices(ctx
, ~0);
1043 _tnl_install_attrs(ctx
,
1044 intel
->vertex_attrs
,
1045 intel
->vertex_attr_count
,
1046 intel
->ViewportMatrix
.m
, 0);
1048 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1060 /**********************************************************************/
1061 /* Used only with the metaops callbacks. */
1062 /**********************************************************************/
1064 intel_meta_draw_poly(struct intel_context
*intel
,
1067 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1072 /* All 3d primitives should be emitted with INTEL_BATCH_CLIPRECTS,
1073 * otherwise the drawing origin (DR4) might not be set correctly.
1075 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, INTEL_BATCH_CLIPRECTS
);
1076 vb
= (union fi
*) intelExtendInlinePrimitive(intel
, n
* 6);
1078 for (i
= 0; i
< n
; i
++) {
1083 vb
[4].f
= tex
[i
][0];
1084 vb
[5].f
= tex
[i
][1];
1088 INTEL_FIREVERTICES(intel
);
1092 intel_meta_draw_quad(struct intel_context
*intel
,
1093 GLfloat x0
, GLfloat x1
,
1094 GLfloat y0
, GLfloat y1
,
1097 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1120 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1125 /**********************************************************************/
1126 /* Initialization. */
1127 /**********************************************************************/
1131 intelInitTriFuncs(GLcontext
* ctx
)
1133 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1134 static int firsttime
= 1;
1141 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1142 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1143 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1144 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1145 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1146 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1147 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1148 tnl
->Driver
.Render
.Interp
= _tnl_interp
;