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 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
31 #include "pipe/p_util.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_shader_tokens.h"
35 #include "draw_pipe.h"
38 struct widepoint_stage
{
39 struct draw_stage stage
;
41 float half_point_size
;
48 uint texcoord_slot
[PIPE_MAX_SHADER_OUTPUTS
];
49 uint texcoord_mode
[PIPE_MAX_SHADER_OUTPUTS
];
57 static INLINE
struct widepoint_stage
*
58 widepoint_stage( struct draw_stage
*stage
)
60 return (struct widepoint_stage
*)stage
;
64 static void passthrough_point( struct draw_stage
*stage
,
65 struct prim_header
*header
)
67 stage
->next
->point( stage
->next
, header
);
70 static void widepoint_line( struct draw_stage
*stage
,
71 struct prim_header
*header
)
73 stage
->next
->line(stage
->next
, header
);
76 static void widepoint_tri( struct draw_stage
*stage
,
77 struct prim_header
*header
)
79 stage
->next
->tri(stage
->next
, header
);
84 * Set the vertex texcoords for sprite mode.
85 * Coords may be left untouched or set to a right-side-up or upside-down
88 static void set_texcoords(const struct widepoint_stage
*wide
,
89 struct vertex_header
*v
, const float tc
[4])
92 for (i
= 0; i
< wide
->num_texcoords
; i
++) {
93 if (wide
->texcoord_mode
[i
] != PIPE_SPRITE_COORD_NONE
) {
94 uint j
= wide
->texcoord_slot
[i
];
95 v
->data
[j
][0] = tc
[0];
96 if (wide
->texcoord_mode
[i
] == PIPE_SPRITE_COORD_LOWER_LEFT
)
97 v
->data
[j
][1] = 1.0f
- tc
[1];
99 v
->data
[j
][1] = tc
[1];
100 v
->data
[j
][2] = tc
[2];
101 v
->data
[j
][3] = tc
[3];
107 /* If there are lots of sprite points (and why wouldn't there be?) it
108 * would probably be more sensible to change hardware setup to
109 * optimize this rather than doing the whole thing in software like
112 static void widepoint_point( struct draw_stage
*stage
,
113 struct prim_header
*header
)
115 const struct widepoint_stage
*wide
= widepoint_stage(stage
);
116 const boolean sprite
= (boolean
) stage
->draw
->rasterizer
->point_sprite
;
118 float left_adj
, right_adj
, bot_adj
, top_adj
;
120 struct prim_header tri
;
122 /* four dups of original vertex */
123 struct vertex_header
*v0
= dup_vert(stage
, header
->v
[0], 0);
124 struct vertex_header
*v1
= dup_vert(stage
, header
->v
[0], 1);
125 struct vertex_header
*v2
= dup_vert(stage
, header
->v
[0], 2);
126 struct vertex_header
*v3
= dup_vert(stage
, header
->v
[0], 3);
128 float *pos0
= v0
->data
[0];
129 float *pos1
= v1
->data
[0];
130 float *pos2
= v2
->data
[0];
131 float *pos3
= v3
->data
[0];
133 /* point size is either per-vertex or fixed size */
134 if (wide
->psize_slot
>= 0) {
135 half_size
= header
->v
[0]->data
[wide
->psize_slot
][0];
137 /* XXX: temporary -- do this in the vertex shader??
139 half_size
= CLAMP(half_size
,
140 wide
->point_size_min
,
141 wide
->point_size_max
);
146 half_size
= wide
->half_point_size
;
149 left_adj
= -half_size
+ wide
->xbias
;
150 right_adj
= half_size
+ wide
->xbias
;
151 bot_adj
= half_size
+ wide
->ybias
;
152 top_adj
= -half_size
+ wide
->ybias
;
160 pos2
[0] += right_adj
;
163 pos3
[0] += right_adj
;
167 static const float tex00
[4] = { 0, 0, 0, 1 };
168 static const float tex01
[4] = { 0, 1, 0, 1 };
169 static const float tex11
[4] = { 1, 1, 0, 1 };
170 static const float tex10
[4] = { 1, 0, 0, 1 };
171 set_texcoords( wide
, v0
, tex00
);
172 set_texcoords( wide
, v1
, tex01
);
173 set_texcoords( wide
, v2
, tex10
);
174 set_texcoords( wide
, v3
, tex11
);
177 tri
.det
= header
->det
; /* only the sign matters */
181 stage
->next
->tri( stage
->next
, &tri
);
186 stage
->next
->tri( stage
->next
, &tri
);
190 static void widepoint_first_point( struct draw_stage
*stage
,
191 struct prim_header
*header
)
193 struct widepoint_stage
*wide
= widepoint_stage(stage
);
194 struct draw_context
*draw
= stage
->draw
;
196 wide
->half_point_size
= 0.5f
* draw
->rasterizer
->point_size
;
197 wide
->point_size_min
= draw
->rasterizer
->point_size_min
;
198 wide
->point_size_max
= draw
->rasterizer
->point_size_max
;
202 if (draw
->rasterizer
->gl_rasterization_rules
) {
206 /* XXX we won't know the real size if it's computed by the vertex shader! */
207 if ((draw
->rasterizer
->point_size
> draw
->pipeline
.wide_point_threshold
) ||
208 (draw
->rasterizer
->point_sprite
&& draw
->pipeline
.point_sprite
)) {
209 stage
->point
= widepoint_point
;
212 stage
->point
= passthrough_point
;
215 if (draw
->rasterizer
->point_sprite
) {
216 /* find vertex shader texcoord outputs */
217 const struct draw_vertex_shader
*vs
= draw
->vertex_shader
;
219 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
220 if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_GENERIC
) {
221 wide
->texcoord_slot
[j
] = i
;
222 wide
->texcoord_mode
[j
] = draw
->rasterizer
->sprite_coord_mode
[j
];
226 wide
->num_texcoords
= j
;
229 wide
->psize_slot
= -1;
230 if (draw
->rasterizer
->point_size_per_vertex
) {
231 /* find PSIZ vertex output */
232 const struct draw_vertex_shader
*vs
= draw
->vertex_shader
;
234 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
235 if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_PSIZE
) {
236 wide
->psize_slot
= i
;
242 stage
->point( stage
, header
);
246 static void widepoint_flush( struct draw_stage
*stage
, unsigned flags
)
248 stage
->point
= widepoint_first_point
;
249 stage
->next
->flush( stage
->next
, flags
);
253 static void widepoint_reset_stipple_counter( struct draw_stage
*stage
)
255 stage
->next
->reset_stipple_counter( stage
->next
);
259 static void widepoint_destroy( struct draw_stage
*stage
)
261 draw_free_temp_verts( stage
);
266 struct draw_stage
*draw_wide_point_stage( struct draw_context
*draw
)
268 struct widepoint_stage
*wide
= CALLOC_STRUCT(widepoint_stage
);
270 draw_alloc_temp_verts( &wide
->stage
, 4 );
272 wide
->stage
.draw
= draw
;
273 wide
->stage
.next
= NULL
;
274 wide
->stage
.point
= widepoint_first_point
;
275 wide
->stage
.line
= widepoint_line
;
276 wide
->stage
.tri
= widepoint_tri
;
277 wide
->stage
.flush
= widepoint_flush
;
278 wide
->stage
.reset_stipple_counter
= widepoint_reset_stipple_counter
;
279 wide
->stage
.destroy
= widepoint_destroy
;