1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
4  * All Rights Reserved.
5  *
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:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
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 VMWARE 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.
25  *
26  **************************************************************************/
27 
28  /*
29   * Authors:
30   *   Keith Whitwell <keithw@vmware.com>
31   */
32 
33 #include "util/u_memory.h"
34 #include "draw/draw_private.h"
35 #include "draw/draw_pipe.h"
36 
37 
38 
39 void
draw_pipe_passthrough_point(struct draw_stage * stage,struct prim_header * header)40 draw_pipe_passthrough_point(struct draw_stage *stage, struct prim_header *header)
41 {
42    stage->next->point(stage->next, header);
43 }
44 
45 void
draw_pipe_passthrough_line(struct draw_stage * stage,struct prim_header * header)46 draw_pipe_passthrough_line(struct draw_stage *stage, struct prim_header *header)
47 {
48    stage->next->line(stage->next, header);
49 }
50 
51 void
draw_pipe_passthrough_tri(struct draw_stage * stage,struct prim_header * header)52 draw_pipe_passthrough_tri(struct draw_stage *stage, struct prim_header *header)
53 {
54    stage->next->tri(stage->next, header);
55 }
56 
57 
58 
59 
60 
61 /* This is only used for temporary verts.
62  */
63 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
64 
65 
66 /**
67  * Allocate space for temporary post-transform vertices, such as for clipping.
68  */
draw_alloc_temp_verts(struct draw_stage * stage,unsigned nr)69 boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr )
70 {
71    assert(!stage->tmp);
72 
73    stage->tmp = NULL;
74    stage->nr_tmps = nr;
75 
76    if (nr != 0)
77    {
78       unsigned i;
79       ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr +
80                                        DRAW_EXTRA_VERTICES_PADDING );
81       if (!store)
82          return FALSE;
83 
84       stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );
85       if (stage->tmp == NULL) {
86          FREE(store);
87          return FALSE;
88       }
89 
90       for (i = 0; i < nr; i++)
91          stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
92    }
93 
94    return TRUE;
95 }
96 
97 
draw_free_temp_verts(struct draw_stage * stage)98 void draw_free_temp_verts( struct draw_stage *stage )
99 {
100    if (stage->tmp) {
101       FREE( stage->tmp[0] );
102       FREE( stage->tmp );
103       stage->tmp = NULL;
104    }
105 }
106 
107 
108 /* Reset vertex ids.  This is basically a type of flush.
109  *
110  * Called only from draw_pipe_vbuf.c
111  */
draw_reset_vertex_ids(struct draw_context * draw)112 void draw_reset_vertex_ids(struct draw_context *draw)
113 {
114    struct draw_stage *stage = draw->pipeline.first;
115 
116    while (stage) {
117       unsigned i;
118 
119       for (i = 0; i < stage->nr_tmps; i++)
120 	 stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID;
121 
122       stage = stage->next;
123    }
124 
125    if (draw->pipeline.verts)
126    {
127       unsigned i;
128       char *verts = draw->pipeline.verts;
129       unsigned stride = draw->pipeline.vertex_stride;
130 
131       for (i = 0; i < draw->pipeline.vertex_count; i++) {
132          ((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID;
133          verts += stride;
134       }
135    }
136 }
137 
138