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"
34 #include "draw_private.h"
37 struct widepoint_stage
{
38 struct draw_stage stage
;
40 float half_point_size
;
42 uint texcoord_slot
[PIPE_MAX_SHADER_OUTPUTS
];
43 uint texcoord_mode
[PIPE_MAX_SHADER_OUTPUTS
];
51 static INLINE
struct widepoint_stage
*
52 widepoint_stage( struct draw_stage
*stage
)
54 return (struct widepoint_stage
*)stage
;
58 static void passthrough_point( struct draw_stage
*stage
,
59 struct prim_header
*header
)
61 stage
->next
->point( stage
->next
, header
);
64 static void widepoint_line( struct draw_stage
*stage
,
65 struct prim_header
*header
)
67 stage
->next
->line(stage
->next
, header
);
70 static void widepoint_tri( struct draw_stage
*stage
,
71 struct prim_header
*header
)
73 stage
->next
->tri(stage
->next
, header
);
78 * Set the vertex texcoords for sprite mode.
79 * Coords may be left untouched or set to a right-side-up or upside-down
82 static void set_texcoords(const struct widepoint_stage
*wide
,
83 struct vertex_header
*v
, const float tc
[4])
86 for (i
= 0; i
< wide
->num_texcoords
; i
++) {
87 if (wide
->texcoord_mode
[i
] != PIPE_SPRITE_COORD_NONE
) {
88 uint j
= wide
->texcoord_slot
[i
];
89 v
->data
[j
][0] = tc
[0];
90 if (wide
->texcoord_mode
[i
] == PIPE_SPRITE_COORD_LOWER_LEFT
)
91 v
->data
[j
][1] = 1.0f
- tc
[1];
93 v
->data
[j
][1] = tc
[1];
94 v
->data
[j
][2] = tc
[2];
95 v
->data
[j
][3] = tc
[3];
101 /* If there are lots of sprite points (and why wouldn't there be?) it
102 * would probably be more sensible to change hardware setup to
103 * optimize this rather than doing the whole thing in software like
106 static void widepoint_point( struct draw_stage
*stage
,
107 struct prim_header
*header
)
109 const struct widepoint_stage
*wide
= widepoint_stage(stage
);
110 const boolean sprite
= (boolean
) stage
->draw
->rasterizer
->point_sprite
;
112 float left_adj
, right_adj
, bot_adj
, top_adj
;
114 struct prim_header tri
;
116 /* four dups of original vertex */
117 struct vertex_header
*v0
= dup_vert(stage
, header
->v
[0], 0);
118 struct vertex_header
*v1
= dup_vert(stage
, header
->v
[0], 1);
119 struct vertex_header
*v2
= dup_vert(stage
, header
->v
[0], 2);
120 struct vertex_header
*v3
= dup_vert(stage
, header
->v
[0], 3);
122 float *pos0
= v0
->data
[0];
123 float *pos1
= v1
->data
[0];
124 float *pos2
= v2
->data
[0];
125 float *pos3
= v3
->data
[0];
127 const float xbias
= 0.0, ybias
= -0.125;
129 /* point size is either per-vertex or fixed size */
130 if (wide
->psize_slot
>= 0) {
131 half_size
= 0.5f
* header
->v
[0]->data
[wide
->psize_slot
][0];
134 half_size
= wide
->half_point_size
;
137 left_adj
= -half_size
+ xbias
;
138 right_adj
= half_size
+ xbias
;
139 bot_adj
= half_size
+ ybias
;
140 top_adj
= -half_size
+ ybias
;
148 pos2
[0] += right_adj
;
151 pos3
[0] += right_adj
;
155 static const float tex00
[4] = { 0, 0, 0, 1 };
156 static const float tex01
[4] = { 0, 1, 0, 1 };
157 static const float tex11
[4] = { 1, 1, 0, 1 };
158 static const float tex10
[4] = { 1, 0, 0, 1 };
159 set_texcoords( wide
, v0
, tex00
);
160 set_texcoords( wide
, v1
, tex01
);
161 set_texcoords( wide
, v2
, tex10
);
162 set_texcoords( wide
, v3
, tex11
);
165 tri
.det
= header
->det
; /* only the sign matters */
169 stage
->next
->tri( stage
->next
, &tri
);
174 stage
->next
->tri( stage
->next
, &tri
);
178 static void widepoint_first_point( struct draw_stage
*stage
,
179 struct prim_header
*header
)
181 struct widepoint_stage
*wide
= widepoint_stage(stage
);
182 struct draw_context
*draw
= stage
->draw
;
184 wide
->half_point_size
= 0.5f
* draw
->rasterizer
->point_size
;
186 /* XXX we won't know the real size if it's computed by the vertex shader! */
187 if (draw
->rasterizer
->point_size
> draw
->wide_point_threshold
) {
188 stage
->point
= widepoint_point
;
191 stage
->point
= passthrough_point
;
194 if (draw
->rasterizer
->point_sprite
) {
195 /* find vertex shader texcoord outputs */
196 const struct draw_vertex_shader
*vs
= draw
->vertex_shader
;
198 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
199 if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_GENERIC
) {
200 wide
->texcoord_slot
[j
] = i
;
201 wide
->texcoord_mode
[j
] = draw
->rasterizer
->sprite_coord_mode
[j
];
205 wide
->num_texcoords
= j
;
208 wide
->psize_slot
= -1;
209 if (draw
->rasterizer
->point_size_per_vertex
) {
210 /* find PSIZ vertex output */
211 const struct draw_vertex_shader
*vs
= draw
->vertex_shader
;
213 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
214 if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_PSIZE
) {
215 wide
->psize_slot
= i
;
221 stage
->point( stage
, header
);
225 static void widepoint_flush( struct draw_stage
*stage
, unsigned flags
)
227 stage
->point
= widepoint_first_point
;
228 stage
->next
->flush( stage
->next
, flags
);
232 static void widepoint_reset_stipple_counter( struct draw_stage
*stage
)
234 stage
->next
->reset_stipple_counter( stage
->next
);
238 static void widepoint_destroy( struct draw_stage
*stage
)
240 draw_free_temp_verts( stage
);
245 struct draw_stage
*draw_wide_point_stage( struct draw_context
*draw
)
247 struct widepoint_stage
*wide
= CALLOC_STRUCT(widepoint_stage
);
249 draw_alloc_temp_verts( &wide
->stage
, 4 );
251 wide
->stage
.draw
= draw
;
252 wide
->stage
.next
= NULL
;
253 wide
->stage
.point
= widepoint_first_point
;
254 wide
->stage
.line
= widepoint_line
;
255 wide
->stage
.tri
= widepoint_tri
;
256 wide
->stage
.flush
= widepoint_flush
;
257 wide
->stage
.reset_stipple_counter
= widepoint_reset_stipple_counter
;
258 wide
->stage
.destroy
= widepoint_destroy
;