1 /**************************************************************************
3 * Copyright 2008 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 **************************************************************************/
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"
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
45 struct draw_context
*draw
;
49 boolean (*run
)( struct pt_post_vs
*pvs
,
50 struct draw_vertex_info
*info
);
54 initialize_vertex_header(struct vertex_header
*header
)
59 header
->vertex_id
= UNDEFINED_VERTEX_ID
;
63 dot4(const float *a
, const float *b
)
72 #define TAG(x) x##_none
73 #include "draw_cliptest_tmp.h"
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"
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"
83 #define FLAGS (DO_CLIP_FULL_Z | DO_VIEWPORT)
84 #define TAG(x) x##_fullz_viewport
85 #include "draw_cliptest_tmp.h"
87 #define FLAGS (DO_CLIP_HALF_Z | DO_VIEWPORT)
88 #define TAG(x) x##_halfz_viewport
89 #include "draw_cliptest_tmp.h"
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"
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"
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
106 #define FLAGS (pvs->flags)
107 #define TAG(x) x##_generic
108 #include "draw_cliptest_tmp.h"
112 boolean
draw_pt_post_vs_run( struct pt_post_vs
*pvs
,
113 struct draw_vertex_info
*info
)
115 return pvs
->run( pvs
, info
);
119 void draw_pt_post_vs_prepare( struct pt_post_vs
*pvs
,
123 boolean bypass_viewport
,
125 boolean need_edgeflags
)
130 pvs
->flags
|= DO_CLIP_XY
;
132 if (clip_z
&& opengl
) {
133 pvs
->flags
|= DO_CLIP_FULL_Z
;
134 ASSIGN_4V( pvs
->draw
->plane
[4], 0, 0, 1, 1 );
137 if (clip_z
&& !opengl
) {
138 pvs
->flags
|= DO_CLIP_HALF_Z
;
139 ASSIGN_4V( pvs
->draw
->plane
[4], 0, 0, 1, 0 );
143 pvs
->flags
|= DO_CLIP_USER
;
145 if (!bypass_viewport
)
146 pvs
->flags
|= DO_VIEWPORT
;
149 pvs
->flags
|= DO_EDGEFLAG
;
151 /* Now select the relevant function:
153 switch (pvs
->flags
) {
155 pvs
->run
= do_cliptest_none
;
158 case DO_CLIP_XY
| DO_CLIP_FULL_Z
| DO_VIEWPORT
:
159 pvs
->run
= do_cliptest_xy_fullz_viewport
;
162 case DO_CLIP_XY
| DO_CLIP_HALF_Z
| DO_VIEWPORT
:
163 pvs
->run
= do_cliptest_xy_halfz_viewport
;
166 case DO_CLIP_FULL_Z
| DO_VIEWPORT
:
167 pvs
->run
= do_cliptest_fullz_viewport
;
170 case DO_CLIP_HALF_Z
| DO_VIEWPORT
:
171 pvs
->run
= do_cliptest_halfz_viewport
;
174 case DO_CLIP_XY
| DO_CLIP_FULL_Z
| DO_CLIP_USER
| DO_VIEWPORT
:
175 pvs
->run
= do_cliptest_xy_fullz_user_viewport
;
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
;
184 pvs
->run
= do_cliptest_generic
;
190 struct pt_post_vs
*draw_pt_post_vs_create( struct draw_context
*draw
)
192 struct pt_post_vs
*pvs
= CALLOC_STRUCT( pt_post_vs
);
201 void draw_pt_post_vs_destroy( struct pt_post_vs
*pvs
)