1 /**************************************************************************
3 * Copyright 2007 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 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "pipe/p_util.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_private.h"
36 #include "draw/draw_vertex.h"
37 #include "draw/draw_pt.h"
38 #include "draw/draw_pipe.h"
40 static void do_point( struct draw_context
*draw
,
43 struct prim_header prim
;
45 prim
.reset_line_stipple
= 0;
48 prim
.v
[0] = (struct vertex_header
*)v0
;
50 draw
->pipeline
.first
->point( draw
->pipeline
.first
, &prim
);
54 static void do_line( struct draw_context
*draw
,
58 struct prim_header prim
;
60 prim
.reset_line_stipple
= 1; /* fixme */
63 prim
.v
[0] = (struct vertex_header
*)v0
;
64 prim
.v
[1] = (struct vertex_header
*)v1
;
66 draw
->pipeline
.first
->line( draw
->pipeline
.first
, &prim
);
70 static void do_triangle( struct draw_context
*draw
,
75 struct prim_header prim
;
77 prim
.v
[0] = (struct vertex_header
*)v0
;
78 prim
.v
[1] = (struct vertex_header
*)v1
;
79 prim
.v
[2] = (struct vertex_header
*)v2
;
80 prim
.reset_line_stipple
= 1;
81 prim
.edgeflags
= ((prim
.v
[0]->edgeflag
) |
82 (prim
.v
[1]->edgeflag
<< 1) |
83 (prim
.v
[2]->edgeflag
<< 2));
86 if (0) debug_printf("tri ef: %d %d %d\n",
91 draw
->pipeline
.first
->tri( draw
->pipeline
.first
, &prim
);
96 void draw_pt_reset_vertex_ids( struct draw_context
*draw
)
99 char *verts
= draw
->pt
.pipeline
.verts
;
100 unsigned stride
= draw
->pt
.pipeline
.vertex_stride
;
102 for (i
= 0; i
< draw
->pt
.pipeline
.vertex_count
; i
++) {
103 ((struct vertex_header
*)verts
)->vertex_id
= UNDEFINED_VERTEX_ID
;
109 /* Code to run the pipeline on a fairly arbitary collection of vertices.
111 * Vertex headers must be pre-initialized with the
112 * UNDEFINED_VERTEX_ID, this code will cause that id to become
113 * overwritten, so it may have to be reset if there is the intention
114 * to reuse the vertices.
116 * This code provides a callback to reset the vertex id's which the
117 * draw_vbuf.c code uses when it has to perform a flush.
119 void draw_pt_run_pipeline( struct draw_context
*draw
,
121 struct vertex_header
*pipeline_verts
,
122 unsigned vertex_count
,
127 char *verts
= (char *)pipeline_verts
;
130 draw
->pt
.pipeline
.verts
= verts
;
131 draw
->pt
.pipeline
.vertex_stride
= stride
;
132 draw
->pt
.pipeline
.vertex_count
= vertex_count
;
135 case PIPE_PRIM_POINTS
:
136 for (i
= 0; i
< count
; i
++)
138 verts
+ stride
* elts
[i
] );
140 case PIPE_PRIM_LINES
:
141 for (i
= 0; i
+1 < count
; i
+= 2)
143 verts
+ stride
* elts
[i
+0],
144 verts
+ stride
* elts
[i
+1]);
146 case PIPE_PRIM_TRIANGLES
:
147 for (i
= 0; i
+2 < count
; i
+= 3)
149 verts
+ stride
* elts
[i
+0],
150 verts
+ stride
* elts
[i
+1],
151 verts
+ stride
* elts
[i
+2]);
155 draw
->pt
.pipeline
.verts
= NULL
;
156 draw
->pt
.pipeline
.vertex_count
= 0;