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
)
188 GLuint vertsize
= intel
->vertex_size
;
189 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 6 * vertsize
);
192 COPY_DWORDS(j
, vb
, vertsize
, v0
);
193 COPY_DWORDS(j
, vb
, vertsize
, v1
);
195 /* If smooth shading, draw like a trifan which gives better
196 * rasterization. Otherwise draw as two triangles with provoking
197 * vertex in third position as required for flat shading.
199 if (intel
->ctx
.Light
.ShadeModel
== GL_FLAT
) {
200 COPY_DWORDS(j
, vb
, vertsize
, v3
);
201 COPY_DWORDS(j
, vb
, vertsize
, v1
);
204 COPY_DWORDS(j
, vb
, vertsize
, v2
);
205 COPY_DWORDS(j
, vb
, vertsize
, v0
);
208 COPY_DWORDS(j
, vb
, vertsize
, v2
);
209 COPY_DWORDS(j
, vb
, vertsize
, v3
);
213 intel_draw_triangle(struct intel_context
*intel
,
214 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
216 GLuint vertsize
= intel
->vertex_size
;
217 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 3 * vertsize
);
220 COPY_DWORDS(j
, vb
, vertsize
, v0
);
221 COPY_DWORDS(j
, vb
, vertsize
, v1
);
222 COPY_DWORDS(j
, vb
, vertsize
, v2
);
227 intel_draw_line(struct intel_context
*intel
,
228 intelVertexPtr v0
, intelVertexPtr v1
)
230 GLuint vertsize
= intel
->vertex_size
;
231 GLuint
*vb
= intelExtendInlinePrimitive(intel
, 2 * vertsize
);
234 COPY_DWORDS(j
, vb
, vertsize
, v0
);
235 COPY_DWORDS(j
, vb
, vertsize
, v1
);
240 intel_draw_point(struct intel_context
*intel
, intelVertexPtr v0
)
242 GLuint vertsize
= intel
->vertex_size
;
243 GLuint
*vb
= intelExtendInlinePrimitive(intel
, vertsize
);
246 /* Adjust for sub pixel position -- still required for conform. */
247 *(float *) &vb
[0] = v0
->v
.x
- 0.125;
248 *(float *) &vb
[1] = v0
->v
.y
- 0.125;
249 for (j
= 2; j
< vertsize
; j
++)
255 /***********************************************************************
256 * Fixup for ARB_point_parameters *
257 ***********************************************************************/
259 /* Currently not working - VERT_ATTRIB_POINTSIZE isn't correctly
260 * represented in the fragment program InputsRead field.
263 intel_atten_point(struct intel_context
*intel
, intelVertexPtr v0
)
265 GLcontext
*ctx
= &intel
->ctx
;
266 GLfloat psz
[4], col
[4], restore_psz
, restore_alpha
;
268 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
269 _tnl_get_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
271 restore_psz
= psz
[0];
272 restore_alpha
= col
[3];
274 if (psz
[0] >= ctx
->Point
.Threshold
) {
275 psz
[0] = MIN2(psz
[0], ctx
->Point
.MaxSize
);
278 GLfloat dsize
= psz
[0] / ctx
->Point
.Threshold
;
279 psz
[0] = MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
);
280 col
[3] *= dsize
* dsize
;
286 if (restore_psz
!= psz
[0] || restore_alpha
!= col
[3]) {
287 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
288 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
290 intel_draw_point(intel
, v0
);
292 psz
[0] = restore_psz
;
293 col
[3] = restore_alpha
;
295 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_POINTSIZE
, psz
);
296 _tnl_set_attr(ctx
, v0
, _TNL_ATTRIB_COLOR0
, col
);
299 intel_draw_point(intel
, v0
);
306 /***********************************************************************
307 * Fixup for I915 WPOS texture coordinate *
308 ***********************************************************************/
313 intel_wpos_triangle(struct intel_context
*intel
,
314 intelVertexPtr v0
, intelVertexPtr v1
, intelVertexPtr v2
)
316 GLuint offset
= intel
->wpos_offset
;
317 GLuint size
= intel
->wpos_size
;
319 __memcpy(((char *) v0
) + offset
, v0
, size
);
320 __memcpy(((char *) v1
) + offset
, v1
, size
);
321 __memcpy(((char *) v2
) + offset
, v2
, size
);
323 intel_draw_triangle(intel
, v0
, v1
, v2
);
328 intel_wpos_line(struct intel_context
*intel
,
329 intelVertexPtr v0
, intelVertexPtr v1
)
331 GLuint offset
= intel
->wpos_offset
;
332 GLuint size
= intel
->wpos_size
;
334 __memcpy(((char *) v0
) + offset
, v0
, size
);
335 __memcpy(((char *) v1
) + offset
, v1
, size
);
337 intel_draw_line(intel
, v0
, v1
);
342 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
344 GLuint offset
= intel
->wpos_offset
;
345 GLuint size
= intel
->wpos_size
;
347 __memcpy(((char *) v0
) + offset
, v0
, size
);
349 intel_draw_point(intel
, v0
);
357 /***********************************************************************
358 * Macros for t_dd_tritmp.h to draw basic primitives *
359 ***********************************************************************/
361 #define TRI( a, b, c ) \
364 intel->draw_tri( intel, a, b, c ); \
366 intel_draw_triangle( intel, a, b, c ); \
369 #define QUAD( a, b, c, d ) \
372 intel->draw_tri( intel, a, b, d ); \
373 intel->draw_tri( intel, b, c, d ); \
375 intel_draw_quad( intel, a, b, c, d ); \
378 #define LINE( v0, v1 ) \
381 intel->draw_line( intel, v0, v1 ); \
383 intel_draw_line( intel, v0, v1 ); \
386 #define POINT( v0 ) \
389 intel->draw_point( intel, v0 ); \
391 intel_draw_point( intel, v0 ); \
395 /***********************************************************************
396 * Build render functions from dd templates *
397 ***********************************************************************/
399 #define INTEL_OFFSET_BIT 0x01
400 #define INTEL_TWOSIDE_BIT 0x02
401 #define INTEL_UNFILLED_BIT 0x04
402 #define INTEL_FALLBACK_BIT 0x08
403 #define INTEL_MAX_TRIFUNC 0x10
408 tnl_points_func points
;
410 tnl_triangle_func triangle
;
412 } rast_tab
[INTEL_MAX_TRIFUNC
];
415 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
416 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
417 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
418 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
424 #define DO_FULL_QUAD 1
428 #define HAVE_BACK_COLORS 0
429 #define HAVE_HW_FLATSHADE 1
430 #define VERTEX intelVertex
433 /* Only used to pull back colors into vertices (ie, we know color is
436 #define INTEL_COLOR( dst, src ) \
438 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
439 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
440 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
441 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
444 #define INTEL_SPEC( 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]); \
452 #define DEPTH_SCALE intel->polygon_offset_scale
453 #define UNFILLED_TRI unfilled_tri
454 #define UNFILLED_QUAD unfilled_quad
455 #define VERT_X(_v) _v->v.x
456 #define VERT_Y(_v) _v->v.y
457 #define VERT_Z(_v) _v->v.z
458 #define AREA_IS_CCW( a ) (a > 0)
459 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
461 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
462 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
463 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
464 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
466 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
467 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
468 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
469 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
471 #define LOCAL_VARS(n) \
472 struct intel_context *intel = intel_context(ctx); \
473 GLuint color[n], spec[n]; \
474 GLuint coloroffset = intel->coloroffset; \
475 GLboolean specoffset = intel->specoffset; \
476 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
479 /***********************************************************************
480 * Helpers for rendering unfilled primitives *
481 ***********************************************************************/
483 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
496 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
497 #define RENDER_PRIMITIVE intel->render_primitive
499 #define IND INTEL_FALLBACK_BIT
500 #include "tnl_dd/t_dd_unfilled.h"
503 /***********************************************************************
504 * Generate GL render functions *
505 ***********************************************************************/
509 #include "tnl_dd/t_dd_tritmp.h"
511 #define IND (INTEL_OFFSET_BIT)
512 #define TAG(x) x##_offset
513 #include "tnl_dd/t_dd_tritmp.h"
515 #define IND (INTEL_TWOSIDE_BIT)
516 #define TAG(x) x##_twoside
517 #include "tnl_dd/t_dd_tritmp.h"
519 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
520 #define TAG(x) x##_twoside_offset
521 #include "tnl_dd/t_dd_tritmp.h"
523 #define IND (INTEL_UNFILLED_BIT)
524 #define TAG(x) x##_unfilled
525 #include "tnl_dd/t_dd_tritmp.h"
527 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
528 #define TAG(x) x##_offset_unfilled
529 #include "tnl_dd/t_dd_tritmp.h"
531 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
532 #define TAG(x) x##_twoside_unfilled
533 #include "tnl_dd/t_dd_tritmp.h"
535 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
536 #define TAG(x) x##_twoside_offset_unfilled
537 #include "tnl_dd/t_dd_tritmp.h"
539 #define IND (INTEL_FALLBACK_BIT)
540 #define TAG(x) x##_fallback
541 #include "tnl_dd/t_dd_tritmp.h"
543 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
544 #define TAG(x) x##_offset_fallback
545 #include "tnl_dd/t_dd_tritmp.h"
547 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
548 #define TAG(x) x##_twoside_fallback
549 #include "tnl_dd/t_dd_tritmp.h"
551 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
552 #define TAG(x) x##_twoside_offset_fallback
553 #include "tnl_dd/t_dd_tritmp.h"
555 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
556 #define TAG(x) x##_unfilled_fallback
557 #include "tnl_dd/t_dd_tritmp.h"
559 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
560 #define TAG(x) x##_offset_unfilled_fallback
561 #include "tnl_dd/t_dd_tritmp.h"
563 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
564 #define TAG(x) x##_twoside_unfilled_fallback
565 #include "tnl_dd/t_dd_tritmp.h"
567 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
569 #define TAG(x) x##_twoside_offset_unfilled_fallback
570 #include "tnl_dd/t_dd_tritmp.h"
579 init_twoside_offset();
581 init_offset_unfilled();
582 init_twoside_unfilled();
583 init_twoside_offset_unfilled();
585 init_offset_fallback();
586 init_twoside_fallback();
587 init_twoside_offset_fallback();
588 init_unfilled_fallback();
589 init_offset_unfilled_fallback();
590 init_twoside_unfilled_fallback();
591 init_twoside_offset_unfilled_fallback();
595 /***********************************************************************
596 * Rasterization fallback helpers *
597 ***********************************************************************/
600 /* This code is hit only when a mix of accelerated and unaccelerated
601 * primitives are being drawn, and only for the unaccelerated
605 intel_fallback_tri(struct intel_context
*intel
,
606 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
608 GLcontext
*ctx
= &intel
->ctx
;
612 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
614 INTEL_FIREVERTICES(intel
);
616 _swsetup_Translate(ctx
, v0
, &v
[0]);
617 _swsetup_Translate(ctx
, v1
, &v
[1]);
618 _swsetup_Translate(ctx
, v2
, &v
[2]);
619 intelSpanRenderStart(ctx
);
620 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
621 intelSpanRenderFinish(ctx
);
626 intel_fallback_line(struct intel_context
*intel
,
627 intelVertex
* v0
, intelVertex
* v1
)
629 GLcontext
*ctx
= &intel
->ctx
;
633 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
635 INTEL_FIREVERTICES(intel
);
637 _swsetup_Translate(ctx
, v0
, &v
[0]);
638 _swsetup_Translate(ctx
, v1
, &v
[1]);
639 intelSpanRenderStart(ctx
);
640 _swrast_Line(ctx
, &v
[0], &v
[1]);
641 intelSpanRenderFinish(ctx
);
645 intel_fallback_point(struct intel_context
*intel
,
648 GLcontext
*ctx
= &intel
->ctx
;
652 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
654 INTEL_FIREVERTICES(intel
);
656 _swsetup_Translate(ctx
, v0
, &v
[0]);
657 intelSpanRenderStart(ctx
);
658 _swrast_Point(ctx
, &v
[0]);
659 intelSpanRenderFinish(ctx
);
663 /**********************************************************************/
664 /* Render unclipped begin/end objects */
665 /**********************************************************************/
668 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
669 #define RENDER_POINTS( start, count ) \
670 for ( ; start < count ; start++) POINT( V(ELT(start)) );
671 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
672 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
673 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
674 #define INIT(x) intelRenderPrimitive( ctx, x )
677 struct intel_context *intel = intel_context(ctx); \
678 GLubyte *vertptr = (GLubyte *)intel->verts; \
679 const GLuint vertsize = intel->vertex_size; \
680 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
682 #define RESET_STIPPLE
683 #define RESET_OCCLUSION
684 #define PRESERVE_VB_DEFS
686 #define TAG(x) intel_##x##_verts
687 #include "tnl/t_vb_rendertmp.h"
690 #define TAG(x) intel_##x##_elts
691 #define ELT(x) elt[x]
692 #include "tnl/t_vb_rendertmp.h"
694 /**********************************************************************/
695 /* Render clipped primitives */
696 /**********************************************************************/
701 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
703 struct intel_context
*intel
= intel_context(ctx
);
704 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
705 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
706 GLuint prim
= intel
->render_primitive
;
708 /* Render the new vertices as an unclipped polygon.
711 GLuint
*tmp
= VB
->Elts
;
712 VB
->Elts
= (GLuint
*) elts
;
713 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
714 PRIM_BEGIN
| PRIM_END
);
718 /* Restore the render primitive
720 if (prim
!= GL_POLYGON
)
721 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
725 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
727 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
729 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
733 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
735 struct intel_context
*intel
= intel_context(ctx
);
736 const GLuint vertsize
= intel
->vertex_size
;
737 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
738 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
739 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
742 for (i
= 2; i
< n
; i
++) {
743 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
744 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
745 COPY_DWORDS(j
, vb
, vertsize
, start
);
749 /**********************************************************************/
750 /* Choose render functions */
751 /**********************************************************************/
756 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
757 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
760 intelChooseRenderState(GLcontext
* ctx
)
762 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
763 struct intel_context
*intel
= intel_context(ctx
);
764 GLuint flags
= ctx
->_TriangleCaps
;
765 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
766 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
769 if (INTEL_DEBUG
& DEBUG_STATE
)
770 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
772 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
774 if (flags
& ANY_RASTER_FLAGS
) {
775 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
776 index
|= INTEL_TWOSIDE_BIT
;
777 if (flags
& DD_TRI_OFFSET
)
778 index
|= INTEL_OFFSET_BIT
;
779 if (flags
& DD_TRI_UNFILLED
)
780 index
|= INTEL_UNFILLED_BIT
;
784 intel
->draw_point
= intel_wpos_point
;
785 intel
->draw_line
= intel_wpos_line
;
786 intel
->draw_tri
= intel_wpos_triangle
;
788 /* Make sure these get called:
790 index
|= INTEL_FALLBACK_BIT
;
793 intel
->draw_point
= intel_draw_point
;
794 intel
->draw_line
= intel_draw_line
;
795 intel
->draw_tri
= intel_draw_triangle
;
798 /* Hook in fallbacks for specific primitives.
800 if (flags
& ANY_FALLBACK_FLAGS
) {
801 if (flags
& DD_LINE_STIPPLE
)
802 intel
->draw_line
= intel_fallback_line
;
804 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
805 intel
->draw_tri
= intel_fallback_tri
;
807 if (flags
& DD_TRI_SMOOTH
) {
808 if (intel
->strict_conformance
)
809 intel
->draw_tri
= intel_fallback_tri
;
812 if (flags
& DD_POINT_ATTEN
) {
814 intel
->draw_point
= intel_atten_point
;
816 intel
->draw_point
= intel_fallback_point
;
819 if (flags
& DD_POINT_SMOOTH
) {
820 if (intel
->strict_conformance
)
821 intel
->draw_point
= intel_fallback_point
;
824 index
|= INTEL_FALLBACK_BIT
;
828 if (intel
->RenderIndex
!= index
) {
829 intel
->RenderIndex
= index
;
831 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
832 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
833 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
834 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
837 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
838 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
839 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
840 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
843 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
844 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
845 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
846 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
851 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
865 /**********************************************************************/
866 /* High level hooks for t_vb_render.c */
867 /**********************************************************************/
873 intelRunPipeline(GLcontext
* ctx
)
875 struct intel_context
*intel
= intel_context(ctx
);
877 _mesa_lock_context_textures(ctx
);
880 _mesa_update_state_locked(ctx
);
882 if (intel
->NewGLState
) {
883 if (intel
->NewGLState
& _NEW_TEXTURE
) {
884 intel
->vtbl
.update_texture_state(intel
);
887 if (!intel
->Fallback
) {
888 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
889 intelChooseRenderState(ctx
);
892 intel
->NewGLState
= 0;
895 _tnl_run_pipeline(ctx
);
897 _mesa_unlock_context_textures(ctx
);
901 intelRenderStart(GLcontext
* ctx
)
903 struct intel_context
*intel
= intel_context(ctx
);
905 intel
->vtbl
.render_start(intel_context(ctx
));
906 intel
->vtbl
.emit_state(intel
);
910 intelRenderFinish(GLcontext
* ctx
)
912 struct intel_context
*intel
= intel_context(ctx
);
914 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
917 INTEL_FIREVERTICES(intel
);
923 /* System to flush dma and emit state changes based on the rasterized
927 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
929 struct intel_context
*intel
= intel_context(ctx
);
932 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
933 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
935 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
937 /* Start a new primitive. Arrange to have it flushed later on.
939 if (hwprim
!= intel
->prim
.primitive
) {
940 INTEL_FIREVERTICES(intel
);
942 intelStartInlinePrimitive(intel
, hwprim
, INTEL_BATCH_CLIPRECTS
);
950 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
952 struct intel_context
*intel
= intel_context(ctx
);
955 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
957 /* Let some clipping routines know which primitive they're dealing
960 intel
->render_primitive
= prim
;
962 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
963 * triangles. The rasterized primitive will always be reset by
964 * lower level functions in that case, potentially pingponging the
967 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
968 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
971 /* Set some primitive-dependent state and Start? a new primitive.
973 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
977 /**********************************************************************/
978 /* Transition to/from hardware rasterization. */
979 /**********************************************************************/
981 static char *fallbackStrings
[] = {
984 [2] = "Depth buffer",
985 [3] = "Stencil buffer",
986 [4] = "User disable",
995 [18] = "Smooth polygon",
996 [19] = "Smooth point",
1001 getFallbackString(GLuint bit
)
1008 return fallbackStrings
[i
];
1014 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1016 GLcontext
*ctx
= &intel
->ctx
;
1017 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1018 GLuint oldfallback
= intel
->Fallback
;
1021 intel
->Fallback
|= bit
;
1022 if (oldfallback
== 0) {
1024 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1025 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1026 bit
, getFallbackString(bit
));
1027 _swsetup_Wakeup(ctx
);
1028 intel
->RenderIndex
= ~0;
1032 intel
->Fallback
&= ~bit
;
1033 if (oldfallback
== bit
) {
1035 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1036 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1037 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1038 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1039 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1040 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1041 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1042 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1044 _tnl_invalidate_vertex_state(ctx
, ~0);
1045 _tnl_invalidate_vertices(ctx
, ~0);
1046 _tnl_install_attrs(ctx
,
1047 intel
->vertex_attrs
,
1048 intel
->vertex_attr_count
,
1049 intel
->ViewportMatrix
.m
, 0);
1051 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1063 /**********************************************************************/
1064 /* Used only with the metaops callbacks. */
1065 /**********************************************************************/
1067 intel_meta_draw_poly(struct intel_context
*intel
,
1070 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1075 /* All 3d primitives should be emitted with INTEL_BATCH_CLIPRECTS,
1076 * otherwise the drawing origin (DR4) might not be set correctly.
1078 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, INTEL_BATCH_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
);
1095 intel_meta_draw_quad(struct intel_context
*intel
,
1096 GLfloat x0
, GLfloat x1
,
1097 GLfloat y0
, GLfloat y1
,
1100 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1123 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1128 /**********************************************************************/
1129 /* Initialization. */
1130 /**********************************************************************/
1134 intelInitTriFuncs(GLcontext
* ctx
)
1136 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1137 static int firsttime
= 1;
1144 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1145 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1146 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1147 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1148 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1149 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1150 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1151 tnl
->Driver
.Render
.Interp
= _tnl_interp
;