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_wait_flips(intel
);
94 intel
->vtbl
.emit_state(intel
);
96 intel
->no_batch_wrap
= GL_TRUE
;
98 /* _mesa_printf("%s *", __progname); */
100 /* Emit a slot which will be filled with the inline primitive
103 BEGIN_BATCH(2, batch_flags
);
106 assert((intel
->batch
->dirty_state
& (1<<1)) == 0);
108 intel
->prim
.start_ptr
= intel
->batch
->ptr
;
109 intel
->prim
.primitive
= prim
;
110 intel
->prim
.flush
= intel_flush_inline_primitive
;
115 intel
->no_batch_wrap
= GL_FALSE
;
117 /* _mesa_printf(">"); */
122 intelWrapInlinePrimitive(struct intel_context
*intel
)
124 GLuint prim
= intel
->prim
.primitive
;
125 enum cliprect_mode cliprect_mode
= intel
->batch
->cliprect_mode
;
127 intel_flush_inline_primitive(intel
);
128 intel_batchbuffer_flush(intel
->batch
);
129 intelStartInlinePrimitive(intel
, prim
, cliprect_mode
); /* ??? */
133 intelExtendInlinePrimitive(struct intel_context
*intel
, GLuint dwords
)
135 GLuint sz
= dwords
* sizeof(GLuint
);
138 assert(intel
->prim
.flush
== intel_flush_inline_primitive
);
140 if (intel_batchbuffer_space(intel
->batch
) < sz
)
141 intelWrapInlinePrimitive(intel
);
143 /* _mesa_printf("."); */
145 intel
->vtbl
.assert_not_dirty(intel
);
147 ptr
= (GLuint
*) intel
->batch
->ptr
;
148 intel
->batch
->ptr
+= sz
;
155 /***********************************************************************
156 * Emit primitives as inline vertices *
157 ***********************************************************************/
160 #define COPY_DWORDS( j, vb, vertsize, v ) \
163 __asm__ __volatile__( "rep ; movsl" \
164 : "=%c" (j), "=D" (vb), "=S" (__tmp) \
170 #define COPY_DWORDS( j, vb, vertsize, v ) \
172 for ( j = 0 ; j < vertsize ; j++ ) { \
173 vb[j] = ((GLuint *)v)[j]; \
180 intel_draw_quad(struct intel_context
*intel
,
182 intelVertexPtr v1
, intelVertexPtr v2
, intelVertexPtr v3
)
184 GLuint vertsize
= intel
->vertex_size
;
185 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 6 * vertsize
);
188 COPY_DWORDS(j
, vb
, vertsize
, v0
);
189 COPY_DWORDS(j
, vb
, vertsize
, v1
);
191 /* If smooth shading, draw like a trifan which gives better
192 * rasterization. Otherwise draw as two triangles with provoking
193 * vertex in third position as required for flat shading.
195 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
196 COPY_DWORDS(j
, vb
, vertsize
, v3
);
197 COPY_DWORDS(j
, vb
, vertsize
, v1
);
200 COPY_DWORDS(j
, vb
, vertsize
, v2
);
201 COPY_DWORDS(j
, vb
, vertsize
, v0
);
204 COPY_DWORDS(j
, vb
, vertsize
, v2
);
205 COPY_DWORDS(j
, vb
, vertsize
, v3
);
209 intel_draw_triangle(struct intel_context
*intel
,
210 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
212 GLuint vertsize
= intel
->vertex_size
;
213 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 3 * vertsize
);
216 COPY_DWORDS(j
, vb
, vertsize
, v0
);
217 COPY_DWORDS(j
, vb
, vertsize
, v1
);
218 COPY_DWORDS(j
, vb
, vertsize
, v2
);
223 intel_draw_line(struct intel_context
*intel
,
224 intelVertexPtr v0
, intelVertexPtr v1
)
226 GLuint vertsize
= intel
->vertex_size
;
227 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 2 * vertsize
);
230 COPY_DWORDS(j
, vb
, vertsize
, v0
);
231 COPY_DWORDS(j
, vb
, vertsize
, v1
);
236 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
238 GLuint vertsize
= intel
->vertex_size
;
239 GLuint
*vb
= intelExtendInlinePrimitive(intel
, vertsize
);
242 /* Adjust for sub pixel position -- still required for conform. */
243 *(float *) &vb
[0] = v0
->v
.x
;
244 *(float *) &vb
[1] = v0
->v
.y
;
245 for (j
= 2; j
< vertsize
; j
++)
251 /***********************************************************************
252 * Fixup for ARB_point_parameters *
253 ***********************************************************************/
255 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
256 * represented in the fragment program InputsRead field.
259 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
261 GLcontext
*ctx
= &intel
->ctx
;
262 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
264 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
265 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
267 restore_psz
= psz
[0];
268 restore_alpha
= col
[3];
270 if (psz
[0] >= ctx
->Point
.Threshold
) {
271 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
274 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
275 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
276 col
[3] *= dsize
* dsize
;
282 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
283 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
284 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
286 intel_draw_point(intel
, v0
);
288 psz
[0] = restore_psz
;
289 col
[3] = restore_alpha
;
291 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
292 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
295 intel_draw_point(intel
, v0
);
302 /***********************************************************************
303 * Fixup for I915 WPOS texture coordinate *
304 ***********************************************************************/
309 intel_wpos_triangle(struct intel_context
*intel
,
310 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
312 GLuint offset
= intel
->wpos_offset
;
313 GLuint size
= intel
->wpos_size
;
315 __memcpy(((char *) v0
) + offset
, v0
, size
);
316 __memcpy(((char *) v1
) + offset
, v1
, size
);
317 __memcpy(((char *) v2
) + offset
, v2
, size
);
319 intel_draw_triangle(intel
, v0
, v1
, v2
);
324 intel_wpos_line(struct intel_context
*intel
,
325 intelVertexPtr v0
, intelVertexPtr v1
)
327 GLuint offset
= intel
->wpos_offset
;
328 GLuint size
= intel
->wpos_size
;
330 __memcpy(((char *) v0
) + offset
, v0
, size
);
331 __memcpy(((char *) v1
) + offset
, v1
, size
);
333 intel_draw_line(intel
, v0
, v1
);
338 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
340 GLuint offset
= intel
->wpos_offset
;
341 GLuint size
= intel
->wpos_size
;
343 __memcpy(((char *) v0
) + offset
, v0
, size
);
345 intel_draw_point(intel
, v0
);
353 /***********************************************************************
354 * Macros for t_dd_tritmp.h to draw basic primitives *
355 ***********************************************************************/
357 #define TRI( a, b, c ) \
360 intel->draw_tri( intel, a, b, c ); \
362 intel_draw_triangle( intel, a, b, c ); \
365 #define QUAD( a, b, c, d ) \
368 intel->draw_tri( intel, a, b, d ); \
369 intel->draw_tri( intel, b, c, d ); \
371 intel_draw_quad( intel, a, b, c, d ); \
374 #define LINE( v0, v1 ) \
377 intel->draw_line( intel, v0, v1 ); \
379 intel_draw_line( intel, v0, v1 ); \
382 #define POINT( v0 ) \
385 intel->draw_point( intel, v0 ); \
387 intel_draw_point( intel, v0 ); \
391 /***********************************************************************
392 * Build render functions from dd templates *
393 ***********************************************************************/
395 #define INTEL_OFFSET_BIT 0x01
396 #define INTEL_TWOSIDE_BIT 0x02
397 #define INTEL_UNFILLED_BIT 0x04
398 #define INTEL_FALLBACK_BIT 0x08
399 #define INTEL_MAX_TRIFUNC 0x10
404 tnl_points_func points
;
406 tnl_triangle_func triangle
;
408 } rast_tab
[INTEL_MAX_TRIFUNC
];
411 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
412 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
413 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
414 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
420 #define DO_FULL_QUAD 1
424 #define HAVE_BACK_COLORS 0
425 #define HAVE_HW_FLATSHADE 1
426 #define VERTEX intelVertex
429 /* Only used to pull back colors into vertices (ie, we know color is
432 #define INTEL_COLOR( dst, src ) \
434 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
435 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
436 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
437 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
440 #define INTEL_SPEC( dst, src ) \
442 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
443 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
444 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
448 #define DEPTH_SCALE intel->polygon_offset_scale
449 #define UNFILLED_TRI unfilled_tri
450 #define UNFILLED_QUAD unfilled_quad
451 #define VERT_X(_v) _v->v.x
452 #define VERT_Y(_v) _v->v.y
453 #define VERT_Z(_v) _v->v.z
454 #define AREA_IS_CCW( a ) (a > 0)
455 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
457 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
458 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
459 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
460 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
462 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
463 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
464 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
465 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
467 #define LOCAL_VARS(n) \
468 struct intel_context *intel = intel_context(ctx); \
469 GLuint color[n], spec[n]; \
470 GLuint coloroffset = intel->coloroffset; \
471 GLboolean specoffset = intel->specoffset; \
472 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
475 /***********************************************************************
476 * Helpers for rendering unfilled primitives *
477 ***********************************************************************/
479 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
492 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
493 #define RENDER_PRIMITIVE intel->render_primitive
495 #define IND INTEL_FALLBACK_BIT
496 #include "tnl_dd/t_dd_unfilled.h"
499 /***********************************************************************
500 * Generate GL render functions *
501 ***********************************************************************/
505 #include "tnl_dd/t_dd_tritmp.h"
507 #define IND (INTEL_OFFSET_BIT)
508 #define TAG(x) x##_offset
509 #include "tnl_dd/t_dd_tritmp.h"
511 #define IND (INTEL_TWOSIDE_BIT)
512 #define TAG(x) x##_twoside
513 #include "tnl_dd/t_dd_tritmp.h"
515 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
516 #define TAG(x) x##_twoside_offset
517 #include "tnl_dd/t_dd_tritmp.h"
519 #define IND (INTEL_UNFILLED_BIT)
520 #define TAG(x) x##_unfilled
521 #include "tnl_dd/t_dd_tritmp.h"
523 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
524 #define TAG(x) x##_offset_unfilled
525 #include "tnl_dd/t_dd_tritmp.h"
527 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
528 #define TAG(x) x##_twoside_unfilled
529 #include "tnl_dd/t_dd_tritmp.h"
531 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
532 #define TAG(x) x##_twoside_offset_unfilled
533 #include "tnl_dd/t_dd_tritmp.h"
535 #define IND (INTEL_FALLBACK_BIT)
536 #define TAG(x) x##_fallback
537 #include "tnl_dd/t_dd_tritmp.h"
539 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
540 #define TAG(x) x##_offset_fallback
541 #include "tnl_dd/t_dd_tritmp.h"
543 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
544 #define TAG(x) x##_twoside_fallback
545 #include "tnl_dd/t_dd_tritmp.h"
547 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
548 #define TAG(x) x##_twoside_offset_fallback
549 #include "tnl_dd/t_dd_tritmp.h"
551 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
552 #define TAG(x) x##_unfilled_fallback
553 #include "tnl_dd/t_dd_tritmp.h"
555 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
556 #define TAG(x) x##_offset_unfilled_fallback
557 #include "tnl_dd/t_dd_tritmp.h"
559 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
560 #define TAG(x) x##_twoside_unfilled_fallback
561 #include "tnl_dd/t_dd_tritmp.h"
563 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
565 #define TAG(x) x##_twoside_offset_unfilled_fallback
566 #include "tnl_dd/t_dd_tritmp.h"
575 init_twoside_offset();
577 init_offset_unfilled();
578 init_twoside_unfilled();
579 init_twoside_offset_unfilled();
581 init_offset_fallback();
582 init_twoside_fallback();
583 init_twoside_offset_fallback();
584 init_unfilled_fallback();
585 init_offset_unfilled_fallback();
586 init_twoside_unfilled_fallback();
587 init_twoside_offset_unfilled_fallback();
591 /***********************************************************************
592 * Rasterization fallback helpers *
593 ***********************************************************************/
596 /* This code is hit only when a mix of accelerated and unaccelerated
597 * primitives are being drawn, and only for the unaccelerated
601 intel_fallback_tri(struct intel_context
*intel
,
602 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
604 GLcontext
*ctx
= &intel
->ctx
;
608 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
610 INTEL_FIREVERTICES(intel
);
612 _swsetup_Translate(ctx
, v0
, &v
[0]);
613 _swsetup_Translate(ctx
, v1
, &v
[1]);
614 _swsetup_Translate(ctx
, v2
, &v
[2]);
615 intelSpanRenderStart(ctx
);
616 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
617 intelSpanRenderFinish(ctx
);
622 intel_fallback_line(struct intel_context
*intel
,
623 intelVertex
* v0
, intelVertex
* v1
)
625 GLcontext
*ctx
= &intel
->ctx
;
629 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
631 INTEL_FIREVERTICES(intel
);
633 _swsetup_Translate(ctx
, v0
, &v
[0]);
634 _swsetup_Translate(ctx
, v1
, &v
[1]);
635 intelSpanRenderStart(ctx
);
636 _swrast_Line(ctx
, &v
[0], &v
[1]);
637 intelSpanRenderFinish(ctx
);
641 intel_fallback_point(struct intel_context
*intel
,
644 GLcontext
*ctx
= &intel
->ctx
;
648 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
650 INTEL_FIREVERTICES(intel
);
652 _swsetup_Translate(ctx
, v0
, &v
[0]);
653 intelSpanRenderStart(ctx
);
654 _swrast_Point(ctx
, &v
[0]);
655 intelSpanRenderFinish(ctx
);
659 /**********************************************************************/
660 /* Render unclipped begin/end objects */
661 /**********************************************************************/
664 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
665 #define RENDER_POINTS( start, count ) \
666 for ( ; start < count ; start++) POINT( V(ELT(start)) );
667 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
668 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
669 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
670 #define INIT(x) intelRenderPrimitive( ctx, x )
673 struct intel_context *intel = intel_context(ctx); \
674 GLubyte *vertptr = (GLubyte *)intel->verts; \
675 const GLuint vertsize = intel->vertex_size; \
676 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
678 #define RESET_STIPPLE
679 #define RESET_OCCLUSION
680 #define PRESERVE_VB_DEFS
682 #define TAG(x) intel_##x##_verts
683 #include "tnl/t_vb_rendertmp.h"
686 #define TAG(x) intel_##x##_elts
687 #define ELT(x) elt[x]
688 #include "tnl/t_vb_rendertmp.h"
690 /**********************************************************************/
691 /* Render clipped primitives */
692 /**********************************************************************/
697 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
699 struct intel_context
*intel
= intel_context(ctx
);
700 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
701 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
702 GLuint prim
= intel
->render_primitive
;
704 /* Render the new vertices as an unclipped polygon.
707 GLuint
*tmp
= VB
->Elts
;
708 VB
->Elts
= (GLuint
*) elts
;
709 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
710 PRIM_BEGIN
| PRIM_END
);
714 /* Restore the render primitive
716 if (prim
!= GL_POLYGON
)
717 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
721 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
723 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
725 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
729 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
731 struct intel_context
*intel
= intel_context(ctx
);
732 const GLuint vertsize
= intel
->vertex_size
;
733 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
734 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
735 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
738 for (i
= 2; i
< n
; i
++) {
739 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
740 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
741 COPY_DWORDS(j
, vb
, vertsize
, start
);
745 /**********************************************************************/
746 /* Choose render functions */
747 /**********************************************************************/
752 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
753 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
756 intelChooseRenderState(GLcontext
* ctx
)
758 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
759 struct intel_context
*intel
= intel_context(ctx
);
760 GLuint flags
= ctx
->_TriangleCaps
;
761 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
762 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
765 if (INTEL_DEBUG
& DEBUG_STATE
)
766 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
768 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
770 if (flags
& ANY_RASTER_FLAGS
) {
771 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
772 index
|= INTEL_TWOSIDE_BIT
;
773 if (flags
& DD_TRI_OFFSET
)
774 index
|= INTEL_OFFSET_BIT
;
775 if (flags
& DD_TRI_UNFILLED
)
776 index
|= INTEL_UNFILLED_BIT
;
780 intel
->draw_point
= intel_wpos_point
;
781 intel
->draw_line
= intel_wpos_line
;
782 intel
->draw_tri
= intel_wpos_triangle
;
784 /* Make sure these get called:
786 index
|= INTEL_FALLBACK_BIT
;
789 intel
->draw_point
= intel_draw_point
;
790 intel
->draw_line
= intel_draw_line
;
791 intel
->draw_tri
= intel_draw_triangle
;
794 /* Hook in fallbacks for specific primitives.
796 if (flags
& ANY_FALLBACK_FLAGS
) {
797 if (flags
& DD_LINE_STIPPLE
)
798 intel
->draw_line
= intel_fallback_line
;
800 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
801 intel
->draw_tri
= intel_fallback_tri
;
803 if (flags
& DD_TRI_SMOOTH
) {
804 if (intel
->strict_conformance
)
805 intel
->draw_tri
= intel_fallback_tri
;
808 if (flags
& DD_POINT_ATTEN
) {
810 intel
->draw_point
= intel_atten_point
;
812 intel
->draw_point
= intel_fallback_point
;
815 if (flags
& DD_POINT_SMOOTH
) {
816 if (intel
->strict_conformance
)
817 intel
->draw_point
= intel_fallback_point
;
820 index
|= INTEL_FALLBACK_BIT
;
824 if (intel
->RenderIndex
!= index
) {
825 intel
->RenderIndex
= index
;
827 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
828 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
829 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
830 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
833 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
834 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
835 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
836 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
839 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
840 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
841 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
842 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
847 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
861 /**********************************************************************/
862 /* High level hooks for t_vb_render.c */
863 /**********************************************************************/
869 intelRunPipeline(GLcontext
* ctx
)
871 struct intel_context
*intel
= intel_context(ctx
);
873 _mesa_lock_context_textures(ctx
);
876 _mesa_update_state_locked(ctx
);
878 if (intel
->NewGLState
) {
879 if (intel
->NewGLState
& _NEW_TEXTURE
) {
880 intel
->vtbl
.update_texture_state(intel
);
883 if (!intel
->Fallback
) {
884 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
885 intelChooseRenderState(ctx
);
888 intel
->NewGLState
= 0;
891 _tnl_run_pipeline(ctx
);
893 _mesa_unlock_context_textures(ctx
);
897 intelRenderStart(GLcontext
* ctx
)
899 struct intel_context
*intel
= intel_context(ctx
);
901 intel
->vtbl
.render_start(intel_context(ctx
));
902 intel
->vtbl
.emit_state(intel
);
906 intelRenderFinish(GLcontext
* ctx
)
908 struct intel_context
*intel
= intel_context(ctx
);
910 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
913 INTEL_FIREVERTICES(intel
);
919 /* System to flush dma and emit state changes based on the rasterized
923 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
925 struct intel_context
*intel
= intel_context(ctx
);
928 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
929 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
931 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
933 /* Start a new primitive. Arrange to have it flushed later on.
935 if (hwprim
!= intel
->prim
.primitive
) {
936 INTEL_FIREVERTICES(intel
);
938 intelStartInlinePrimitive(intel
, hwprim
, LOOP_CLIPRECTS
);
946 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
948 struct intel_context
*intel
= intel_context(ctx
);
951 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
953 /* Let some clipping routines know which primitive they're dealing
956 intel
->render_primitive
= prim
;
958 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
959 * triangles. The rasterized primitive will always be reset by
960 * lower level functions in that case, potentially pingponging the
963 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
964 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
967 /* Set some primitive-dependent state and Start? a new primitive.
969 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
973 /**********************************************************************/
974 /* Transition to/from hardware rasterization. */
975 /**********************************************************************/
977 static char *fallbackStrings
[] = {
980 [2] = "Depth buffer",
981 [3] = "Stencil buffer",
982 [4] = "User disable",
991 [18] = "Smooth polygon",
992 [19] = "Smooth point",
997 getFallbackString(GLuint bit
)
1004 return fallbackStrings
[i
];
1010 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1012 GLcontext
*ctx
= &intel
->ctx
;
1013 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1014 GLuint oldfallback
= intel
->Fallback
;
1017 intel
->Fallback
|= bit
;
1018 if (oldfallback
== 0) {
1020 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1021 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1022 bit
, getFallbackString(bit
));
1023 _swsetup_Wakeup(ctx
);
1024 intel
->RenderIndex
= ~0;
1028 intel
->Fallback
&= ~bit
;
1029 if (oldfallback
== bit
) {
1031 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1032 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1033 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1034 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1035 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1036 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1037 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1038 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1040 _tnl_invalidate_vertex_state(ctx
, ~0);
1041 _tnl_invalidate_vertices(ctx
, ~0);
1042 _tnl_install_attrs(ctx
,
1043 intel
->vertex_attrs
,
1044 intel
->vertex_attr_count
,
1045 intel
->ViewportMatrix
.m
, 0);
1047 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1059 /**********************************************************************/
1060 /* Used only with the metaops callbacks. */
1061 /**********************************************************************/
1063 intel_meta_draw_poly(struct intel_context
*intel
,
1066 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1070 GLboolean was_locked
= intel
->locked
;
1073 LOCK_HARDWARE(intel
);
1075 /* All 3d primitives should be emitted with LOOP_CLIPRECTS,
1076 * otherwise the drawing origin (DR4) might not be set correctly.
1078 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, LOOP_CLIPRECTS
);
1079 vb
= (union fi
*) intelExtendInlinePrimitive(intel
, n
* 6);
1081 for (i
= 0; i
< n
; i
++) {
1086 vb
[4].f
= tex
[i
][0];
1087 vb
[5].f
= tex
[i
][1];
1091 INTEL_FIREVERTICES(intel
);
1094 UNLOCK_HARDWARE(intel
);
1098 intel_meta_draw_quad(struct intel_context
*intel
,
1099 GLfloat x0
, GLfloat x1
,
1100 GLfloat y0
, GLfloat y1
,
1103 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1126 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1131 /**********************************************************************/
1132 /* Initialization. */
1133 /**********************************************************************/
1137 intelInitTriFuncs(GLcontext
* ctx
)
1139 struct intel_context
*intel
= intel_context(ctx
);
1140 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1141 static int firsttime
= 1;
1148 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1149 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1150 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1151 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1152 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1153 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1154 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1155 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1157 intel
->vtbl
.meta_draw_quad
= intel_meta_draw_quad
;