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
;
314 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
315 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
316 GLfloat
*v2_wpos
= (GLfloat
*)((char *)v2
+ offset
);
318 __memcpy(v0_wpos
, v0
, size
);
319 __memcpy(v1_wpos
, v1
, size
);
320 __memcpy(v2_wpos
, v2
, size
);
322 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
323 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
324 v2_wpos
[1] = -v2_wpos
[1] + intel
->driDrawable
->h
;
327 intel_draw_triangle(intel
, v0
, v1
, v2
);
332 intel_wpos_line(struct intel_context
*intel
,
333 intelVertexPtr v0
, intelVertexPtr v1
)
335 GLuint offset
= intel
->wpos_offset
;
336 GLuint size
= intel
->wpos_size
;
337 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
338 GLfloat
*v1_wpos
= (GLfloat
*)((char *)v1
+ offset
);
340 __memcpy(v0_wpos
, v0
, size
);
341 __memcpy(v1_wpos
, v1
, size
);
343 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
344 v1_wpos
[1] = -v1_wpos
[1] + intel
->driDrawable
->h
;
346 intel_draw_line(intel
, v0
, v1
);
351 intel_wpos_point(struct intel_context
*intel
, intelVertexPtr v0
)
353 GLuint offset
= intel
->wpos_offset
;
354 GLuint size
= intel
->wpos_size
;
355 GLfloat
*v0_wpos
= (GLfloat
*)((char *)v0
+ offset
);
357 __memcpy(v0_wpos
, v0
, size
);
358 v0_wpos
[1] = -v0_wpos
[1] + intel
->driDrawable
->h
;
360 intel_draw_point(intel
, v0
);
368 /***********************************************************************
369 * Macros for t_dd_tritmp.h to draw basic primitives *
370 ***********************************************************************/
372 #define TRI( a, b, c ) \
375 intel->draw_tri( intel, a, b, c ); \
377 intel_draw_triangle( intel, a, b, c ); \
380 #define QUAD( a, b, c, d ) \
383 intel->draw_tri( intel, a, b, d ); \
384 intel->draw_tri( intel, b, c, d ); \
386 intel_draw_quad( intel, a, b, c, d ); \
389 #define LINE( v0, v1 ) \
392 intel->draw_line( intel, v0, v1 ); \
394 intel_draw_line( intel, v0, v1 ); \
397 #define POINT( v0 ) \
400 intel->draw_point( intel, v0 ); \
402 intel_draw_point( intel, v0 ); \
406 /***********************************************************************
407 * Build render functions from dd templates *
408 ***********************************************************************/
410 #define INTEL_OFFSET_BIT 0x01
411 #define INTEL_TWOSIDE_BIT 0x02
412 #define INTEL_UNFILLED_BIT 0x04
413 #define INTEL_FALLBACK_BIT 0x08
414 #define INTEL_MAX_TRIFUNC 0x10
419 tnl_points_func points
;
421 tnl_triangle_func triangle
;
423 } rast_tab
[INTEL_MAX_TRIFUNC
];
426 #define DO_FALLBACK (IND & INTEL_FALLBACK_BIT)
427 #define DO_OFFSET (IND & INTEL_OFFSET_BIT)
428 #define DO_UNFILLED (IND & INTEL_UNFILLED_BIT)
429 #define DO_TWOSIDE (IND & INTEL_TWOSIDE_BIT)
435 #define DO_FULL_QUAD 1
439 #define HAVE_BACK_COLORS 0
440 #define HAVE_HW_FLATSHADE 1
441 #define VERTEX intelVertex
444 /* Only used to pull back colors into vertices (ie, we know color is
447 #define INTEL_COLOR( dst, src ) \
449 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
450 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
451 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
452 UNCLAMPED_FLOAT_TO_UBYTE((dst)[3], (src)[3]); \
455 #define INTEL_SPEC( dst, src ) \
457 UNCLAMPED_FLOAT_TO_UBYTE((dst)[0], (src)[2]); \
458 UNCLAMPED_FLOAT_TO_UBYTE((dst)[1], (src)[1]); \
459 UNCLAMPED_FLOAT_TO_UBYTE((dst)[2], (src)[0]); \
463 #define DEPTH_SCALE intel->polygon_offset_scale
464 #define UNFILLED_TRI unfilled_tri
465 #define UNFILLED_QUAD unfilled_quad
466 #define VERT_X(_v) _v->v.x
467 #define VERT_Y(_v) _v->v.y
468 #define VERT_Z(_v) _v->v.z
469 #define AREA_IS_CCW( a ) (a > 0)
470 #define GET_VERTEX(e) (intel->verts + (e * intel->vertex_size * sizeof(GLuint)))
472 #define VERT_SET_RGBA( v, c ) if (coloroffset) INTEL_COLOR( v->ub4[coloroffset], c )
473 #define VERT_COPY_RGBA( v0, v1 ) if (coloroffset) v0->ui[coloroffset] = v1->ui[coloroffset]
474 #define VERT_SAVE_RGBA( idx ) if (coloroffset) color[idx] = v[idx]->ui[coloroffset]
475 #define VERT_RESTORE_RGBA( idx ) if (coloroffset) v[idx]->ui[coloroffset] = color[idx]
477 #define VERT_SET_SPEC( v, c ) if (specoffset) INTEL_SPEC( v->ub4[specoffset], c )
478 #define VERT_COPY_SPEC( v0, v1 ) if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])
479 #define VERT_SAVE_SPEC( idx ) if (specoffset) spec[idx] = v[idx]->ui[specoffset]
480 #define VERT_RESTORE_SPEC( idx ) if (specoffset) v[idx]->ui[specoffset] = spec[idx]
482 #define LOCAL_VARS(n) \
483 struct intel_context *intel = intel_context(ctx); \
484 GLuint color[n] = { 0, }, spec[n] = { 0, }; \
485 GLuint coloroffset = intel->coloroffset; \
486 GLboolean specoffset = intel->specoffset; \
487 (void) color; (void) spec; (void) coloroffset; (void) specoffset;
490 /***********************************************************************
491 * Helpers for rendering unfilled primitives *
492 ***********************************************************************/
494 static const GLuint hw_prim
[GL_POLYGON
+ 1] = {
507 #define RASTERIZE(x) intelRasterPrimitive( ctx, x, hw_prim[x] )
508 #define RENDER_PRIMITIVE intel->render_primitive
510 #define IND INTEL_FALLBACK_BIT
511 #include "tnl_dd/t_dd_unfilled.h"
514 /***********************************************************************
515 * Generate GL render functions *
516 ***********************************************************************/
520 #include "tnl_dd/t_dd_tritmp.h"
522 #define IND (INTEL_OFFSET_BIT)
523 #define TAG(x) x##_offset
524 #include "tnl_dd/t_dd_tritmp.h"
526 #define IND (INTEL_TWOSIDE_BIT)
527 #define TAG(x) x##_twoside
528 #include "tnl_dd/t_dd_tritmp.h"
530 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT)
531 #define TAG(x) x##_twoside_offset
532 #include "tnl_dd/t_dd_tritmp.h"
534 #define IND (INTEL_UNFILLED_BIT)
535 #define TAG(x) x##_unfilled
536 #include "tnl_dd/t_dd_tritmp.h"
538 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
539 #define TAG(x) x##_offset_unfilled
540 #include "tnl_dd/t_dd_tritmp.h"
542 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT)
543 #define TAG(x) x##_twoside_unfilled
544 #include "tnl_dd/t_dd_tritmp.h"
546 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT)
547 #define TAG(x) x##_twoside_offset_unfilled
548 #include "tnl_dd/t_dd_tritmp.h"
550 #define IND (INTEL_FALLBACK_BIT)
551 #define TAG(x) x##_fallback
552 #include "tnl_dd/t_dd_tritmp.h"
554 #define IND (INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
555 #define TAG(x) x##_offset_fallback
556 #include "tnl_dd/t_dd_tritmp.h"
558 #define IND (INTEL_TWOSIDE_BIT|INTEL_FALLBACK_BIT)
559 #define TAG(x) x##_twoside_fallback
560 #include "tnl_dd/t_dd_tritmp.h"
562 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_FALLBACK_BIT)
563 #define TAG(x) x##_twoside_offset_fallback
564 #include "tnl_dd/t_dd_tritmp.h"
566 #define IND (INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
567 #define TAG(x) x##_unfilled_fallback
568 #include "tnl_dd/t_dd_tritmp.h"
570 #define IND (INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
571 #define TAG(x) x##_offset_unfilled_fallback
572 #include "tnl_dd/t_dd_tritmp.h"
574 #define IND (INTEL_TWOSIDE_BIT|INTEL_UNFILLED_BIT|INTEL_FALLBACK_BIT)
575 #define TAG(x) x##_twoside_unfilled_fallback
576 #include "tnl_dd/t_dd_tritmp.h"
578 #define IND (INTEL_TWOSIDE_BIT|INTEL_OFFSET_BIT|INTEL_UNFILLED_BIT| \
580 #define TAG(x) x##_twoside_offset_unfilled_fallback
581 #include "tnl_dd/t_dd_tritmp.h"
590 init_twoside_offset();
592 init_offset_unfilled();
593 init_twoside_unfilled();
594 init_twoside_offset_unfilled();
596 init_offset_fallback();
597 init_twoside_fallback();
598 init_twoside_offset_fallback();
599 init_unfilled_fallback();
600 init_offset_unfilled_fallback();
601 init_twoside_unfilled_fallback();
602 init_twoside_offset_unfilled_fallback();
606 /***********************************************************************
607 * Rasterization fallback helpers *
608 ***********************************************************************/
611 /* This code is hit only when a mix of accelerated and unaccelerated
612 * primitives are being drawn, and only for the unaccelerated
616 intel_fallback_tri(struct intel_context
*intel
,
617 intelVertex
* v0
, intelVertex
* v1
, intelVertex
* v2
)
619 GLcontext
*ctx
= &intel
->ctx
;
623 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
625 INTEL_FIREVERTICES(intel
);
627 _swsetup_Translate(ctx
, v0
, &v
[0]);
628 _swsetup_Translate(ctx
, v1
, &v
[1]);
629 _swsetup_Translate(ctx
, v2
, &v
[2]);
630 intelSpanRenderStart(ctx
);
631 _swrast_Triangle(ctx
, &v
[0], &v
[1], &v
[2]);
632 intelSpanRenderFinish(ctx
);
637 intel_fallback_line(struct intel_context
*intel
,
638 intelVertex
* v0
, intelVertex
* v1
)
640 GLcontext
*ctx
= &intel
->ctx
;
644 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
646 INTEL_FIREVERTICES(intel
);
648 _swsetup_Translate(ctx
, v0
, &v
[0]);
649 _swsetup_Translate(ctx
, v1
, &v
[1]);
650 intelSpanRenderStart(ctx
);
651 _swrast_Line(ctx
, &v
[0], &v
[1]);
652 intelSpanRenderFinish(ctx
);
656 intel_fallback_point(struct intel_context
*intel
,
659 GLcontext
*ctx
= &intel
->ctx
;
663 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
665 INTEL_FIREVERTICES(intel
);
667 _swsetup_Translate(ctx
, v0
, &v
[0]);
668 intelSpanRenderStart(ctx
);
669 _swrast_Point(ctx
, &v
[0]);
670 intelSpanRenderFinish(ctx
);
674 /**********************************************************************/
675 /* Render unclipped begin/end objects */
676 /**********************************************************************/
679 #define V(x) (intelVertex *)(vertptr + ((x)*vertsize*sizeof(GLuint)))
680 #define RENDER_POINTS( start, count ) \
681 for ( ; start < count ; start++) POINT( V(ELT(start)) );
682 #define RENDER_LINE( v0, v1 ) LINE( V(v0), V(v1) )
683 #define RENDER_TRI( v0, v1, v2 ) TRI( V(v0), V(v1), V(v2) )
684 #define RENDER_QUAD( v0, v1, v2, v3 ) QUAD( V(v0), V(v1), V(v2), V(v3) )
685 #define INIT(x) intelRenderPrimitive( ctx, x )
688 struct intel_context *intel = intel_context(ctx); \
689 GLubyte *vertptr = (GLubyte *)intel->verts; \
690 const GLuint vertsize = intel->vertex_size; \
691 const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts; \
693 #define RESET_STIPPLE
694 #define RESET_OCCLUSION
695 #define PRESERVE_VB_DEFS
697 #define TAG(x) intel_##x##_verts
698 #include "tnl/t_vb_rendertmp.h"
701 #define TAG(x) intel_##x##_elts
702 #define ELT(x) elt[x]
703 #include "tnl/t_vb_rendertmp.h"
705 /**********************************************************************/
706 /* Render clipped primitives */
707 /**********************************************************************/
712 intelRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
714 struct intel_context
*intel
= intel_context(ctx
);
715 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
716 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
717 GLuint prim
= intel
->render_primitive
;
719 /* Render the new vertices as an unclipped polygon.
722 GLuint
*tmp
= VB
->Elts
;
723 VB
->Elts
= (GLuint
*) elts
;
724 tnl
->Driver
.Render
.PrimTabElts
[GL_POLYGON
] (ctx
, 0, n
,
725 PRIM_BEGIN
| PRIM_END
);
729 /* Restore the render primitive
731 if (prim
!= GL_POLYGON
)
732 tnl
->Driver
.Render
.PrimitiveNotify(ctx
, prim
);
736 intelRenderClippedLine(GLcontext
* ctx
, GLuint ii
, GLuint jj
)
738 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
740 tnl
->Driver
.Render
.Line(ctx
, ii
, jj
);
744 intelFastRenderClippedPoly(GLcontext
* ctx
, const GLuint
* elts
, GLuint n
)
746 struct intel_context
*intel
= intel_context(ctx
);
747 const GLuint vertsize
= intel
->vertex_size
;
748 GLuint
*vb
= intelExtendInlinePrimitive(intel
, (n
- 2) * 3 * vertsize
);
749 GLubyte
*vertptr
= (GLubyte
*) intel
->verts
;
750 const GLuint
*start
= (const GLuint
*) V(elts
[0]);
753 for (i
= 2; i
< n
; i
++) {
754 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
- 1]));
755 COPY_DWORDS(j
, vb
, vertsize
, V(elts
[i
]));
756 COPY_DWORDS(j
, vb
, vertsize
, start
);
760 /**********************************************************************/
761 /* Choose render functions */
762 /**********************************************************************/
767 #define ANY_FALLBACK_FLAGS (DD_LINE_STIPPLE | DD_TRI_STIPPLE | DD_POINT_ATTEN | DD_POINT_SMOOTH | DD_TRI_SMOOTH)
768 #define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE | DD_TRI_OFFSET | DD_TRI_UNFILLED)
771 intelChooseRenderState(GLcontext
* ctx
)
773 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
774 struct intel_context
*intel
= intel_context(ctx
);
775 GLuint flags
= ctx
->_TriangleCaps
;
776 const struct gl_fragment_program
*fprog
= ctx
->FragmentProgram
._Current
;
777 GLboolean have_wpos
= (fprog
&& (fprog
->Base
.InputsRead
& FRAG_BIT_WPOS
));
780 if (INTEL_DEBUG
& DEBUG_STATE
)
781 fprintf(stderr
, "\n%s\n", __FUNCTION__
);
783 if ((flags
& (ANY_FALLBACK_FLAGS
| ANY_RASTER_FLAGS
)) || have_wpos
) {
785 if (flags
& ANY_RASTER_FLAGS
) {
786 if (flags
& DD_TRI_LIGHT_TWOSIDE
)
787 index
|= INTEL_TWOSIDE_BIT
;
788 if (flags
& DD_TRI_OFFSET
)
789 index
|= INTEL_OFFSET_BIT
;
790 if (flags
& DD_TRI_UNFILLED
)
791 index
|= INTEL_UNFILLED_BIT
;
795 intel
->draw_point
= intel_wpos_point
;
796 intel
->draw_line
= intel_wpos_line
;
797 intel
->draw_tri
= intel_wpos_triangle
;
799 /* Make sure these get called:
801 index
|= INTEL_FALLBACK_BIT
;
804 intel
->draw_point
= intel_draw_point
;
805 intel
->draw_line
= intel_draw_line
;
806 intel
->draw_tri
= intel_draw_triangle
;
809 /* Hook in fallbacks for specific primitives.
811 if (flags
& ANY_FALLBACK_FLAGS
) {
812 if (flags
& DD_LINE_STIPPLE
)
813 intel
->draw_line
= intel_fallback_line
;
815 if ((flags
& DD_TRI_STIPPLE
) && !intel
->hw_stipple
)
816 intel
->draw_tri
= intel_fallback_tri
;
818 if (flags
& DD_TRI_SMOOTH
) {
819 if (intel
->strict_conformance
)
820 intel
->draw_tri
= intel_fallback_tri
;
823 if (flags
& DD_POINT_ATTEN
) {
825 intel
->draw_point
= intel_atten_point
;
827 intel
->draw_point
= intel_fallback_point
;
830 if (flags
& DD_POINT_SMOOTH
) {
831 if (intel
->strict_conformance
)
832 intel
->draw_point
= intel_fallback_point
;
835 index
|= INTEL_FALLBACK_BIT
;
839 if (intel
->RenderIndex
!= index
) {
840 intel
->RenderIndex
= index
;
842 tnl
->Driver
.Render
.Points
= rast_tab
[index
].points
;
843 tnl
->Driver
.Render
.Line
= rast_tab
[index
].line
;
844 tnl
->Driver
.Render
.Triangle
= rast_tab
[index
].triangle
;
845 tnl
->Driver
.Render
.Quad
= rast_tab
[index
].quad
;
848 tnl
->Driver
.Render
.PrimTabVerts
= intel_render_tab_verts
;
849 tnl
->Driver
.Render
.PrimTabElts
= intel_render_tab_elts
;
850 tnl
->Driver
.Render
.ClippedLine
= line
; /* from tritmp.h */
851 tnl
->Driver
.Render
.ClippedPolygon
= intelFastRenderClippedPoly
;
854 tnl
->Driver
.Render
.PrimTabVerts
= _tnl_render_tab_verts
;
855 tnl
->Driver
.Render
.PrimTabElts
= _tnl_render_tab_elts
;
856 tnl
->Driver
.Render
.ClippedLine
= intelRenderClippedLine
;
857 tnl
->Driver
.Render
.ClippedPolygon
= intelRenderClippedPoly
;
862 static const GLenum reduced_prim
[GL_POLYGON
+ 1] = {
876 /**********************************************************************/
877 /* High level hooks for t_vb_render.c */
878 /**********************************************************************/
884 intelRunPipeline(GLcontext
* ctx
)
886 struct intel_context
*intel
= intel_context(ctx
);
888 _mesa_lock_context_textures(ctx
);
891 _mesa_update_state_locked(ctx
);
893 if (intel
->NewGLState
) {
894 if (intel
->NewGLState
& _NEW_TEXTURE
) {
895 intel
->vtbl
.update_texture_state(intel
);
898 if (!intel
->Fallback
) {
899 if (intel
->NewGLState
& _INTEL_NEW_RENDERSTATE
)
900 intelChooseRenderState(ctx
);
903 intel
->NewGLState
= 0;
906 _tnl_run_pipeline(ctx
);
908 _mesa_unlock_context_textures(ctx
);
912 intelRenderStart(GLcontext
* ctx
)
914 struct intel_context
*intel
= intel_context(ctx
);
916 intel
->vtbl
.render_start(intel_context(ctx
));
917 intel
->vtbl
.emit_state(intel
);
921 intelRenderFinish(GLcontext
* ctx
)
923 struct intel_context
*intel
= intel_context(ctx
);
925 if (intel
->RenderIndex
& INTEL_FALLBACK_BIT
)
928 INTEL_FIREVERTICES(intel
);
934 /* System to flush dma and emit state changes based on the rasterized
938 intelRasterPrimitive(GLcontext
* ctx
, GLenum rprim
, GLuint hwprim
)
940 struct intel_context
*intel
= intel_context(ctx
);
943 fprintf(stderr
, "%s %s %x\n", __FUNCTION__
,
944 _mesa_lookup_enum_by_nr(rprim
), hwprim
);
946 intel
->vtbl
.reduced_primitive_state(intel
, rprim
);
948 /* Start a new primitive. Arrange to have it flushed later on.
950 if (hwprim
!= intel
->prim
.primitive
) {
951 INTEL_FIREVERTICES(intel
);
953 intelStartInlinePrimitive(intel
, hwprim
, LOOP_CLIPRECTS
);
961 intelRenderPrimitive(GLcontext
* ctx
, GLenum prim
)
963 struct intel_context
*intel
= intel_context(ctx
);
966 fprintf(stderr
, "%s %s\n", __FUNCTION__
, _mesa_lookup_enum_by_nr(prim
));
968 /* Let some clipping routines know which primitive they're dealing
971 intel
->render_primitive
= prim
;
973 /* Shortcircuit this when called from t_dd_rendertmp.h for unfilled
974 * triangles. The rasterized primitive will always be reset by
975 * lower level functions in that case, potentially pingponging the
978 if (reduced_prim
[prim
] == GL_TRIANGLES
&&
979 (ctx
->_TriangleCaps
& DD_TRI_UNFILLED
))
982 /* Set some primitive-dependent state and Start? a new primitive.
984 intelRasterPrimitive(ctx
, reduced_prim
[prim
], hw_prim
[prim
]);
988 /**********************************************************************/
989 /* Transition to/from hardware rasterization. */
990 /**********************************************************************/
992 static char *fallbackStrings
[] = {
995 [2] = "Depth buffer",
996 [3] = "Stencil buffer",
997 [4] = "User disable",
1001 [13] = "Color mask",
1006 [18] = "Smooth polygon",
1007 [19] = "Smooth point",
1012 getFallbackString(GLuint bit
)
1019 return fallbackStrings
[i
];
1025 intelFallback(struct intel_context
*intel
, GLuint bit
, GLboolean mode
)
1027 GLcontext
*ctx
= &intel
->ctx
;
1028 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1029 GLuint oldfallback
= intel
->Fallback
;
1032 intel
->Fallback
|= bit
;
1033 if (oldfallback
== 0) {
1035 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1036 fprintf(stderr
, "ENTER FALLBACK %x: %s\n",
1037 bit
, getFallbackString(bit
));
1038 _swsetup_Wakeup(ctx
);
1039 intel
->RenderIndex
= ~0;
1043 intel
->Fallback
&= ~bit
;
1044 if (oldfallback
== bit
) {
1046 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
1047 fprintf(stderr
, "LEAVE FALLBACK %s\n", getFallbackString(bit
));
1048 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1049 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1050 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1051 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1052 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1053 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1055 _tnl_invalidate_vertex_state(ctx
, ~0);
1056 _tnl_invalidate_vertices(ctx
, ~0);
1057 _tnl_install_attrs(ctx
,
1058 intel
->vertex_attrs
,
1059 intel
->vertex_attr_count
,
1060 intel
->ViewportMatrix
.m
, 0);
1062 intel
->NewGLState
|= _INTEL_NEW_RENDERSTATE
;
1074 /**********************************************************************/
1075 /* Used only with the metaops callbacks. */
1076 /**********************************************************************/
1078 intel_meta_draw_poly(struct intel_context
*intel
,
1081 GLfloat z
, GLuint color
, GLfloat tex
[][2])
1085 GLboolean was_locked
= intel
->locked
;
1088 LOCK_HARDWARE(intel
);
1090 /* All 3d primitives should be emitted with LOOP_CLIPRECTS,
1091 * otherwise the drawing origin (DR4) might not be set correctly.
1093 intelStartInlinePrimitive(intel
, PRIM3D_TRIFAN
, LOOP_CLIPRECTS
);
1094 vb
= (union fi
*) intelExtendInlinePrimitive(intel
, n
* 6);
1096 for (i
= 0; i
< n
; i
++) {
1101 vb
[4].f
= tex
[i
][0];
1102 vb
[5].f
= tex
[i
][1];
1106 INTEL_FIREVERTICES(intel
);
1109 UNLOCK_HARDWARE(intel
);
1113 intel_meta_draw_quad(struct intel_context
*intel
,
1114 GLfloat x0
, GLfloat x1
,
1115 GLfloat y0
, GLfloat y1
,
1118 GLfloat s0
, GLfloat s1
, GLfloat t0
, GLfloat t1
)
1141 intel_meta_draw_poly(intel
, 4, xy
, z
, color
, tex
);
1146 /**********************************************************************/
1147 /* Initialization. */
1148 /**********************************************************************/
1152 intelInitTriFuncs(GLcontext
* ctx
)
1154 struct intel_context
*intel
= intel_context(ctx
);
1155 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1156 static int firsttime
= 1;
1163 tnl
->Driver
.RunPipeline
= intelRunPipeline
;
1164 tnl
->Driver
.Render
.Start
= intelRenderStart
;
1165 tnl
->Driver
.Render
.Finish
= intelRenderFinish
;
1166 tnl
->Driver
.Render
.PrimitiveNotify
= intelRenderPrimitive
;
1167 tnl
->Driver
.Render
.ResetLineStipple
= _swrast_ResetLineStipple
;
1168 tnl
->Driver
.Render
.BuildVertices
= _tnl_build_vertices
;
1169 tnl
->Driver
.Render
.CopyPV
= _tnl_copy_pv
;
1170 tnl
->Driver
.Render
.Interp
= _tnl_interp
;
1172 intel
->vtbl
.meta_draw_quad
= intel_meta_draw_quad
;