Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / draw / draw_pt_post_vs.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 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.
25 *
26 **************************************************************************/
27
28 #include "util/u_memory.h"
29 #include "util/u_math.h"
30 #include "pipe/p_context.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_private.h"
33 #include "draw/draw_pt.h"
34
35
36 #define DO_CLIP_XY 0x1
37 #define DO_CLIP_FULL_Z 0x2
38 #define DO_CLIP_HALF_Z 0x4
39 #define DO_CLIP_USER 0x8
40 #define DO_VIEWPORT 0x10
41 #define DO_EDGEFLAG 0x20
42
43
44 struct pt_post_vs {
45 struct draw_context *draw;
46
47 unsigned flags;
48
49 boolean (*run)( struct pt_post_vs *pvs,
50 struct draw_vertex_info *info );
51 };
52
53 static INLINE void
54 initialize_vertex_header(struct vertex_header *header)
55 {
56 header->clipmask = 0;
57 header->edgeflag = 1;
58 header->pad = 0;
59 header->vertex_id = UNDEFINED_VERTEX_ID;
60 }
61
62 static INLINE float
63 dot4(const float *a, const float *b)
64 {
65 return (a[0]*b[0] +
66 a[1]*b[1] +
67 a[2]*b[2] +
68 a[3]*b[3]);
69 }
70
71 #define FLAGS (0)
72 #define TAG(x) x##_none
73 #include "draw_cliptest_tmp.h"
74
75 #define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT)
76 #define TAG(x) x##_xy_fullz_viewport
77 #include "draw_cliptest_tmp.h"
78
79 #define FLAGS (DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT)
80 #define TAG(x) x##_xy_halfz_viewport
81 #include "draw_cliptest_tmp.h"
82
83 #define FLAGS (DO_CLIP_FULL_Z | DO_VIEWPORT)
84 #define TAG(x) x##_fullz_viewport
85 #include "draw_cliptest_tmp.h"
86
87 #define FLAGS (DO_CLIP_HALF_Z | DO_VIEWPORT)
88 #define TAG(x) x##_halfz_viewport
89 #include "draw_cliptest_tmp.h"
90
91 #define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT)
92 #define TAG(x) x##_xy_fullz_user_viewport
93 #include "draw_cliptest_tmp.h"
94
95 #define FLAGS (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT | DO_EDGEFLAG)
96 #define TAG(x) x##_xy_fullz_user_viewport_edgeflag
97 #include "draw_cliptest_tmp.h"
98
99
100
101 /* Don't want to create 64 versions of this function, so catch the
102 * less common ones here. This is looking like something which should
103 * be code-generated, perhaps appended to the end of the vertex
104 * shader.
105 */
106 #define FLAGS (pvs->flags)
107 #define TAG(x) x##_generic
108 #include "draw_cliptest_tmp.h"
109
110
111
112 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
113 struct draw_vertex_info *info )
114 {
115 return pvs->run( pvs, info );
116 }
117
118
119 void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
120 boolean clip_xy,
121 boolean clip_z,
122 boolean clip_user,
123 boolean bypass_viewport,
124 boolean opengl,
125 boolean need_edgeflags )
126 {
127 pvs->flags = 0;
128
129 if (clip_xy)
130 pvs->flags |= DO_CLIP_XY;
131
132 if (clip_z && opengl) {
133 pvs->flags |= DO_CLIP_FULL_Z;
134 ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 1 );
135 }
136
137 if (clip_z && !opengl) {
138 pvs->flags |= DO_CLIP_HALF_Z;
139 ASSIGN_4V( pvs->draw->plane[4], 0, 0, 1, 0 );
140 }
141
142 if (clip_user)
143 pvs->flags |= DO_CLIP_USER;
144
145 if (!bypass_viewport)
146 pvs->flags |= DO_VIEWPORT;
147
148 if (need_edgeflags)
149 pvs->flags |= DO_EDGEFLAG;
150
151 /* Now select the relevant function:
152 */
153 switch (pvs->flags) {
154 case 0:
155 pvs->run = do_cliptest_none;
156 break;
157
158 case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_VIEWPORT:
159 pvs->run = do_cliptest_xy_fullz_viewport;
160 break;
161
162 case DO_CLIP_XY | DO_CLIP_HALF_Z | DO_VIEWPORT:
163 pvs->run = do_cliptest_xy_halfz_viewport;
164 break;
165
166 case DO_CLIP_FULL_Z | DO_VIEWPORT:
167 pvs->run = do_cliptest_fullz_viewport;
168 break;
169
170 case DO_CLIP_HALF_Z | DO_VIEWPORT:
171 pvs->run = do_cliptest_halfz_viewport;
172 break;
173
174 case DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER | DO_VIEWPORT:
175 pvs->run = do_cliptest_xy_fullz_user_viewport;
176 break;
177
178 case (DO_CLIP_XY | DO_CLIP_FULL_Z | DO_CLIP_USER |
179 DO_VIEWPORT | DO_EDGEFLAG):
180 pvs->run = do_cliptest_xy_fullz_user_viewport_edgeflag;
181 break;
182
183 default:
184 pvs->run = do_cliptest_generic;
185 break;
186 }
187 }
188
189
190 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw )
191 {
192 struct pt_post_vs *pvs = CALLOC_STRUCT( pt_post_vs );
193 if (!pvs)
194 return NULL;
195
196 pvs->draw = draw;
197
198 return pvs;
199 }
200
201 void draw_pt_post_vs_destroy( struct pt_post_vs *pvs )
202 {
203 FREE(pvs);
204 }