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 **************************************************************************/
29 * AA line stage: AA lines are converted to texture mapped triangles.
35 #include "pipe/p_util.h"
36 #include "pipe/p_inlines.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39 #include "pipe/p_shader_tokens.h"
41 #include "tgsi/util/tgsi_transform.h"
42 #include "tgsi/util/tgsi_dump.h"
44 #include "draw_context.h"
45 #include "draw_private.h"
49 * Max texture level for the alpha texture used for antialiasing
51 #define MAX_TEXTURE_LEVEL 5 /* 32 x 32 */
55 * Subclass of pipe_shader_state to carry extra fragment shader info.
57 struct aaline_fragment_shader
59 struct pipe_shader_state state
;
62 void *aapoint_fs
; /* not yet */
63 void *sprite_fs
; /* not yet */
68 * Subclass of draw_stage
72 struct draw_stage stage
;
74 float half_line_width
;
76 /** For AA lines, this is the vertex attrib slot for the new texcoords */
80 struct pipe_texture
*texture
;
85 * Currently bound state
87 struct aaline_fragment_shader
*fs
;
89 void *sampler
[PIPE_MAX_SAMPLERS
];
90 struct pipe_texture
*texture
[PIPE_MAX_SAMPLERS
];
94 * Driver interface/override functions
96 void * (*driver_create_fs_state
)(struct pipe_context
*,
97 const struct pipe_shader_state
*);
98 void (*driver_bind_fs_state
)(struct pipe_context
*, void *);
99 void (*driver_delete_fs_state
)(struct pipe_context
*, void *);
101 void (*driver_bind_sampler_state
)(struct pipe_context
*, unsigned, void *);
103 void (*driver_set_sampler_texture
)(struct pipe_context
*,
105 struct pipe_texture
*);
107 struct pipe_context
*pipe
;
113 * Subclass of tgsi_transform_context, used for transforming the
114 * user's fragment shader to add the special AA instructions.
116 struct aa_transform_context
{
117 struct tgsi_transform_context base
;
118 uint tempsUsed
; /**< bitmask */
119 int colorOutput
; /**< which output is the primary color */
120 int maxSampler
; /**< max sampler index found */
121 int maxInput
, maxGeneric
; /**< max input index found */
122 int colorTemp
, texTemp
; /**< temp registers */
123 boolean firstInstruction
;
128 * TGSI declaration transform callback.
129 * Look for a free sampler, a free input attrib, and two free temp regs.
132 aa_transform_decl(struct tgsi_transform_context
*ctx
,
133 struct tgsi_full_declaration
*decl
)
135 struct aa_transform_context
*aactx
= (struct aa_transform_context
*) ctx
;
137 if (decl
->Declaration
.File
== TGSI_FILE_OUTPUT
&&
138 decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_COLOR
&&
139 decl
->Semantic
.SemanticIndex
== 0) {
140 aactx
->colorOutput
= decl
->u
.DeclarationRange
.First
;
142 else if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER
) {
143 if ((int) decl
->u
.DeclarationRange
.Last
> aactx
->maxSampler
)
144 aactx
->maxSampler
= decl
->u
.DeclarationRange
.Last
+ 1;
146 else if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
147 if ((int) decl
->u
.DeclarationRange
.Last
> aactx
->maxInput
)
148 aactx
->maxInput
= decl
->u
.DeclarationRange
.Last
;
149 if (decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_GENERIC
&&
150 (int) decl
->Semantic
.SemanticIndex
> aactx
->maxGeneric
) {
151 aactx
->maxGeneric
= decl
->Semantic
.SemanticIndex
;
154 else if (decl
->Declaration
.File
== TGSI_FILE_TEMPORARY
) {
156 for (i
= decl
->u
.DeclarationRange
.First
;
157 i
<= decl
->u
.DeclarationRange
.Last
; i
++) {
158 aactx
->tempsUsed
|= (1 << i
);
162 ctx
->emit_declaration(ctx
, decl
);
167 * TGSI instruction transform callback.
168 * Replace writes to result.color w/ a temp reg.
169 * Upon END instruction, insert texture sampling code for antialiasing.
172 aa_transform_inst(struct tgsi_transform_context
*ctx
,
173 struct tgsi_full_instruction
*inst
)
175 struct aa_transform_context
*aactx
= (struct aa_transform_context
*) ctx
;
177 if (aactx
->firstInstruction
) {
178 /* emit our new declarations before the first instruction */
180 struct tgsi_full_declaration decl
;
183 /* find two free temp regs */
184 for (i
= 0; i
< 32; i
++) {
185 if ((aactx
->tempsUsed
& (1 << i
)) == 0) {
186 /* found a free temp */
187 if (aactx
->colorTemp
< 0)
188 aactx
->colorTemp
= i
;
189 else if (aactx
->texTemp
< 0)
195 assert(aactx
->colorTemp
>= 0);
196 assert(aactx
->texTemp
>= 0);
198 /* declare new generic input/texcoord */
199 decl
= tgsi_default_full_declaration();
200 decl
.Declaration
.File
= TGSI_FILE_INPUT
;
201 decl
.Declaration
.Semantic
= 1;
202 decl
.Semantic
.SemanticName
= TGSI_SEMANTIC_GENERIC
;
203 decl
.Semantic
.SemanticIndex
= aactx
->maxGeneric
+ 1;
204 decl
.Declaration
.Interpolate
= 1;
205 /* XXX this could be linear... */
206 decl
.Interpolation
.Interpolate
= TGSI_INTERPOLATE_PERSPECTIVE
;
207 decl
.u
.DeclarationRange
.First
=
208 decl
.u
.DeclarationRange
.Last
= aactx
->maxInput
+ 1;
209 ctx
->emit_declaration(ctx
, &decl
);
211 /* declare new sampler */
212 decl
= tgsi_default_full_declaration();
213 decl
.Declaration
.File
= TGSI_FILE_SAMPLER
;
214 decl
.u
.DeclarationRange
.First
=
215 decl
.u
.DeclarationRange
.Last
= aactx
->maxSampler
+ 1;
216 ctx
->emit_declaration(ctx
, &decl
);
218 /* declare new temp regs */
219 decl
= tgsi_default_full_declaration();
220 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
221 decl
.u
.DeclarationRange
.First
=
222 decl
.u
.DeclarationRange
.Last
= aactx
->texTemp
;
223 ctx
->emit_declaration(ctx
, &decl
);
225 decl
= tgsi_default_full_declaration();
226 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
227 decl
.u
.DeclarationRange
.First
=
228 decl
.u
.DeclarationRange
.Last
= aactx
->colorTemp
;
229 ctx
->emit_declaration(ctx
, &decl
);
231 aactx
->firstInstruction
= FALSE
;
234 if (inst
->Instruction
.Opcode
== TGSI_OPCODE_END
&&
235 aactx
->colorOutput
!= -1) {
236 struct tgsi_full_instruction newInst
;
239 newInst
= tgsi_default_full_instruction();
240 newInst
.Instruction
.Opcode
= TGSI_OPCODE_TEX
;
241 newInst
.Instruction
.NumDstRegs
= 1;
242 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_TEMPORARY
;
243 newInst
.FullDstRegisters
[0].DstRegister
.Index
= aactx
->texTemp
;
244 newInst
.Instruction
.NumSrcRegs
= 2;
245 newInst
.InstructionExtTexture
.Texture
= TGSI_TEXTURE_2D
;
246 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_INPUT
;
247 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= aactx
->maxInput
+ 1;
248 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
249 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= aactx
->maxSampler
+ 1;
251 ctx
->emit_instruction(ctx
, &newInst
);
254 newInst
= tgsi_default_full_instruction();
255 newInst
.Instruction
.Opcode
= TGSI_OPCODE_MOV
;
256 newInst
.Instruction
.NumDstRegs
= 1;
257 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_OUTPUT
;
258 newInst
.FullDstRegisters
[0].DstRegister
.Index
= aactx
->colorOutput
;
259 newInst
.FullDstRegisters
[0].DstRegister
.WriteMask
= TGSI_WRITEMASK_XYZ
;
260 newInst
.Instruction
.NumSrcRegs
= 1;
261 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
262 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= aactx
->colorTemp
;
263 ctx
->emit_instruction(ctx
, &newInst
);
266 newInst
= tgsi_default_full_instruction();
267 newInst
.Instruction
.Opcode
= TGSI_OPCODE_MUL
;
268 newInst
.Instruction
.NumDstRegs
= 1;
269 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_OUTPUT
;
270 newInst
.FullDstRegisters
[0].DstRegister
.Index
= aactx
->colorOutput
;
271 newInst
.FullDstRegisters
[0].DstRegister
.WriteMask
= TGSI_WRITEMASK_W
;
272 newInst
.Instruction
.NumSrcRegs
= 2;
273 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
274 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= aactx
->colorTemp
;
275 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
276 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= aactx
->texTemp
;
277 ctx
->emit_instruction(ctx
, &newInst
);
280 newInst
= tgsi_default_full_instruction();
281 newInst
.Instruction
.Opcode
= TGSI_OPCODE_END
;
282 newInst
.Instruction
.NumDstRegs
= 0;
283 newInst
.Instruction
.NumSrcRegs
= 0;
284 ctx
->emit_instruction(ctx
, &newInst
);
287 /* Not an END instruction.
288 * Look for writes to result.color and replace with colorTemp reg.
292 for (i
= 0; i
< inst
->Instruction
.NumDstRegs
; i
++) {
293 struct tgsi_full_dst_register
*dst
= &inst
->FullDstRegisters
[i
];
294 if (dst
->DstRegister
.File
== TGSI_FILE_OUTPUT
&&
295 dst
->DstRegister
.Index
== aactx
->colorOutput
) {
296 dst
->DstRegister
.File
= TGSI_FILE_TEMPORARY
;
297 dst
->DstRegister
.Index
= aactx
->colorTemp
;
301 ctx
->emit_instruction(ctx
, inst
);
307 * Generate the frag shader we'll use for drawing AA lines.
308 * This will be the user's shader plus some texture/modulate instructions.
311 generate_aaline_fs(struct aaline_stage
*aaline
)
313 const struct pipe_shader_state
*orig_fs
= &aaline
->fs
->state
;
314 struct draw_context
*draw
= aaline
->stage
.draw
;
315 struct pipe_shader_state aaline_fs
;
316 struct aa_transform_context transform
;
320 aaline_fs
= *orig_fs
; /* copy to init */
321 aaline_fs
.tokens
= MALLOC(sizeof(struct tgsi_token
) * MAX
);
323 memset(&transform
, 0, sizeof(transform
));
324 transform
.colorOutput
= -1;
325 transform
.maxSampler
= -1;
326 transform
.maxInput
= -1;
327 transform
.maxGeneric
= -1;
328 transform
.colorTemp
= -1;
329 transform
.texTemp
= -1;
330 transform
.firstInstruction
= TRUE
;
331 transform
.base
.transform_instruction
= aa_transform_inst
;
332 transform
.base
.transform_declaration
= aa_transform_decl
;
334 tgsi_transform_shader(orig_fs
->tokens
,
335 (struct tgsi_token
*) aaline_fs
.tokens
,
336 MAX
, &transform
.base
);
339 tgsi_dump(orig_fs
->tokens
, 0);
340 tgsi_dump(aaline_fs
.tokens
, 0);
343 #if 1 /* XXX remove */
344 aaline_fs
.input_semantic_name
[aaline_fs
.num_inputs
] = TGSI_SEMANTIC_GENERIC
;
345 aaline_fs
.input_semantic_index
[aaline_fs
.num_inputs
] = transform
.maxGeneric
+ 1;
346 aaline_fs
.num_inputs
++;
349 aaline
->fs
->aaline_fs
350 = aaline
->driver_create_fs_state(aaline
->pipe
, &aaline_fs
);
352 /* advertise the extra post-transform vertex attributes which will have
355 draw
->extra_vp_outputs
.semantic_name
= TGSI_SEMANTIC_GENERIC
;
356 draw
->extra_vp_outputs
.semantic_index
= transform
.maxGeneric
+ 1;
361 * Create the texture map we'll use for antialiasing the lines.
364 aaline_create_texture(struct aaline_stage
*aaline
)
366 struct pipe_context
*pipe
= aaline
->pipe
;
367 struct pipe_screen
*screen
= pipe
->screen
;
368 struct pipe_texture texTemp
;
371 memset(&texTemp
, 0, sizeof(texTemp
));
372 texTemp
.target
= PIPE_TEXTURE_2D
;
373 texTemp
.format
= PIPE_FORMAT_U_A8
; /* XXX verify supported by driver! */
374 texTemp
.last_level
= MAX_TEXTURE_LEVEL
;
375 texTemp
.width
[0] = 1 << MAX_TEXTURE_LEVEL
;
376 texTemp
.height
[0] = 1 << MAX_TEXTURE_LEVEL
;
377 texTemp
.depth
[0] = 1;
380 aaline
->texture
= screen
->texture_create(screen
, &texTemp
);
382 /* Fill in mipmap images.
383 * Basically each level is solid opaque, except for the outermost
384 * texels which are zero. Special case the 1x1 and 2x2 levels.
386 for (level
= 0; level
<= MAX_TEXTURE_LEVEL
; level
++) {
387 struct pipe_surface
*surface
;
388 const uint size
= aaline
->texture
->width
[level
];
392 assert(aaline
->texture
->width
[level
] == aaline
->texture
->height
[level
]);
394 surface
= screen
->get_tex_surface(screen
, aaline
->texture
, 0, level
, 0);
395 data
= pipe_surface_map(surface
);
397 for (i
= 0; i
< size
; i
++) {
398 for (j
= 0; j
< size
; j
++) {
403 else if (size
== 2) {
404 d
= 200; /* tuneable */
406 else if (i
== 0 || j
== 0 || i
== size
- 1 || j
== size
- 1) {
412 data
[i
* surface
->pitch
+ j
] = d
;
417 pipe_surface_unmap(surface
);
418 pipe_surface_reference(&surface
, NULL
);
424 * Create the sampler CSO that'll be used for antialiasing.
425 * By using a mipmapped texture, we don't have to generate a different
426 * texture image for each line size.
429 aaline_create_sampler(struct aaline_stage
*aaline
)
431 struct pipe_sampler_state sampler
;
432 struct pipe_context
*pipe
= aaline
->pipe
;
434 memset(&sampler
, 0, sizeof(sampler
));
435 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
436 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
437 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
438 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_LINEAR
;
439 sampler
.min_img_filter
= PIPE_TEX_FILTER_LINEAR
;
440 sampler
.mag_img_filter
= PIPE_TEX_FILTER_LINEAR
;
441 sampler
.normalized_coords
= 1;
442 sampler
.min_lod
= 0.0f
;
443 sampler
.max_lod
= MAX_TEXTURE_LEVEL
;
445 aaline
->sampler_cso
= pipe
->create_sampler_state(pipe
, &sampler
);
450 * When we're about to draw our first AA line in a batch, this function is
451 * called to tell the driver to bind our modified fragment shader.
454 bind_aaline_fragment_shader(struct aaline_stage
*aaline
)
456 if (!aaline
->fs
->aaline_fs
) {
457 generate_aaline_fs(aaline
);
459 aaline
->driver_bind_fs_state(aaline
->pipe
, aaline
->fs
->aaline_fs
);
464 static INLINE
struct aaline_stage
*
465 aaline_stage( struct draw_stage
*stage
)
467 return (struct aaline_stage
*) stage
;
472 passthrough_point(struct draw_stage
*stage
, struct prim_header
*header
)
474 stage
->next
->point(stage
->next
, header
);
479 passthrough_tri(struct draw_stage
*stage
, struct prim_header
*header
)
481 stage
->next
->tri(stage
->next
, header
);
486 * Draw a wide line by drawing a quad, using geometry which will
487 * fullfill GL's antialiased line requirements.
490 aaline_line(struct draw_stage
*stage
, struct prim_header
*header
)
492 const struct aaline_stage
*aaline
= aaline_stage(stage
);
493 const float half_width
= aaline
->half_line_width
;
494 struct prim_header tri
;
495 struct vertex_header
*v
[8];
496 uint texPos
= aaline
->tex_slot
;
498 float dx
= header
->v
[1]->data
[0][0] - header
->v
[0]->data
[0][0];
499 float dy
= header
->v
[1]->data
[0][1] - header
->v
[0]->data
[0][1];
500 double a
= atan2(dy
, dx
);
501 float c_a
= (float) cos(a
), s_a
= (float) sin(a
);
504 /* XXX the ends of lines aren't quite perfect yet, but probably passable */
505 dx
= 0.5F
* half_width
;
508 /* allocate/dup new verts */
509 for (i
= 0; i
< 8; i
++) {
510 v
[i
] = dup_vert(stage
, header
->v
[i
/4], i
);
514 * Quad strip for line from v0 to v1 (*=endpoints):
517 * +---+---------------------+---+
521 * +---+---------------------+---+
527 pos
[0] += (-dx
* c_a
- dy
* s_a
);
528 pos
[1] += (-dx
* s_a
+ dy
* c_a
);
531 pos
[0] += (-dx
* c_a
- -dy
* s_a
);
532 pos
[1] += (-dx
* s_a
+ -dy
* c_a
);
535 pos
[0] += ( dx
* c_a
- dy
* s_a
);
536 pos
[1] += ( dx
* s_a
+ dy
* c_a
);
539 pos
[0] += ( dx
* c_a
- -dy
* s_a
);
540 pos
[1] += ( dx
* s_a
+ -dy
* c_a
);
543 pos
[0] += (-dx
* c_a
- dy
* s_a
);
544 pos
[1] += (-dx
* s_a
+ dy
* c_a
);
547 pos
[0] += (-dx
* c_a
- -dy
* s_a
);
548 pos
[1] += (-dx
* s_a
+ -dy
* c_a
);
551 pos
[0] += ( dx
* c_a
- dy
* s_a
);
552 pos
[1] += ( dx
* s_a
+ dy
* c_a
);
555 pos
[0] += ( dx
* c_a
- -dy
* s_a
);
556 pos
[1] += ( dx
* s_a
+ -dy
* c_a
);
559 tex
= v
[0]->data
[texPos
];
560 ASSIGN_4V(tex
, 0, 0, 0, 1);
562 tex
= v
[1]->data
[texPos
];
563 ASSIGN_4V(tex
, 0, 1, 0, 1);
565 tex
= v
[2]->data
[texPos
];
566 ASSIGN_4V(tex
, .5, 0, 0, 1);
568 tex
= v
[3]->data
[texPos
];
569 ASSIGN_4V(tex
, .5, 1, 0, 1);
571 tex
= v
[4]->data
[texPos
];
572 ASSIGN_4V(tex
, .5, 0, 0, 1);
574 tex
= v
[5]->data
[texPos
];
575 ASSIGN_4V(tex
, .5, 1, 0, 1);
577 tex
= v
[6]->data
[texPos
];
578 ASSIGN_4V(tex
, 1, 0, 0, 1);
580 tex
= v
[7]->data
[texPos
];
581 ASSIGN_4V(tex
, 1, 1, 0, 1);
583 /* emit 6 tris for the quad strip */
584 tri
.v
[0] = v
[2]; tri
.v
[1] = v
[1]; tri
.v
[2] = v
[0];
585 stage
->next
->tri( stage
->next
, &tri
);
587 tri
.v
[0] = v
[3]; tri
.v
[1] = v
[1]; tri
.v
[2] = v
[2];
588 stage
->next
->tri( stage
->next
, &tri
);
590 tri
.v
[0] = v
[4]; tri
.v
[1] = v
[3]; tri
.v
[2] = v
[2];
591 stage
->next
->tri( stage
->next
, &tri
);
593 tri
.v
[0] = v
[5]; tri
.v
[1] = v
[3]; tri
.v
[2] = v
[4];
594 stage
->next
->tri( stage
->next
, &tri
);
596 tri
.v
[0] = v
[6]; tri
.v
[1] = v
[5]; tri
.v
[2] = v
[4];
597 stage
->next
->tri( stage
->next
, &tri
);
599 tri
.v
[0] = v
[7]; tri
.v
[1] = v
[5]; tri
.v
[2] = v
[6];
600 stage
->next
->tri( stage
->next
, &tri
);
605 aaline_first_line(struct draw_stage
*stage
, struct prim_header
*header
)
607 auto struct aaline_stage
*aaline
= aaline_stage(stage
);
608 struct draw_context
*draw
= stage
->draw
;
609 struct pipe_context
*pipe
= aaline
->pipe
;
611 assert(draw
->rasterizer
->line_smooth
);
613 if (draw
->rasterizer
->line_width
<= 3.0)
614 aaline
->half_line_width
= 1.5f
;
616 aaline
->half_line_width
= 0.5f
* draw
->rasterizer
->line_width
;
618 aaline
->tex_slot
= draw
->num_vs_outputs
;
619 assert(aaline
->tex_slot
> 0); /* output[0] is vertex pos */
620 draw
->extra_vp_outputs
.slot
= aaline
->tex_slot
;
623 * Bind our fragprog, sampler and texture
625 bind_aaline_fragment_shader(aaline
);
627 aaline
->driver_bind_sampler_state(pipe
, aaline
->sampler_unit
, aaline
->sampler_cso
);
628 aaline
->driver_set_sampler_texture(pipe
, aaline
->sampler_unit
, aaline
->texture
);
630 /* now really draw first line */
631 stage
->line
= aaline_line
;
632 stage
->line(stage
, header
);
637 aaline_flush(struct draw_stage
*stage
, unsigned flags
)
639 struct draw_context
*draw
= stage
->draw
;
640 struct aaline_stage
*aaline
= aaline_stage(stage
);
641 struct pipe_context
*pipe
= aaline
->pipe
;
643 stage
->line
= aaline_first_line
;
644 stage
->next
->flush( stage
->next
, flags
);
646 /* restore original frag shader */
647 aaline
->driver_bind_fs_state(pipe
, aaline
->fs
->driver_fs
);
649 /* XXX restore original texture, sampler state */
650 aaline
->driver_bind_sampler_state(pipe
, aaline
->sampler_unit
,
651 aaline
->state
.sampler
[aaline
->sampler_unit
]);
652 aaline
->driver_set_sampler_texture(pipe
, aaline
->sampler_unit
,
653 aaline
->state
.texture
[aaline
->sampler_unit
]);
655 draw
->extra_vp_outputs
.slot
= 0;
660 aaline_reset_stipple_counter(struct draw_stage
*stage
)
662 stage
->next
->reset_stipple_counter( stage
->next
);
667 aaline_destroy(struct draw_stage
*stage
)
669 draw_free_temp_verts( stage
);
674 static struct aaline_stage
*
675 draw_aaline_stage(struct draw_context
*draw
)
677 struct aaline_stage
*aaline
= CALLOC_STRUCT(aaline_stage
);
679 draw_alloc_temp_verts( &aaline
->stage
, 8 );
681 aaline
->stage
.draw
= draw
;
682 aaline
->stage
.next
= NULL
;
683 aaline
->stage
.point
= passthrough_point
;
684 aaline
->stage
.line
= aaline_first_line
;
685 aaline
->stage
.tri
= passthrough_tri
;
686 aaline
->stage
.flush
= aaline_flush
;
687 aaline
->stage
.reset_stipple_counter
= aaline_reset_stipple_counter
;
688 aaline
->stage
.destroy
= aaline_destroy
;
694 static struct aaline_stage
*
695 aaline_stage_from_pipe(struct pipe_context
*pipe
)
697 struct draw_context
*draw
= (struct draw_context
*) pipe
->draw
;
698 return aaline_stage(draw
->pipeline
.aaline
);
703 * This function overrides the driver's create_fs_state() function and
704 * will typically be called by the state tracker.
707 aaline_create_fs_state(struct pipe_context
*pipe
,
708 const struct pipe_shader_state
*fs
)
710 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
711 struct aaline_fragment_shader
*aafs
= CALLOC_STRUCT(aaline_fragment_shader
);
717 aafs
->driver_fs
= aaline
->driver_create_fs_state(aaline
->pipe
, fs
);
725 aaline_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
727 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
728 struct aaline_fragment_shader
*aafs
= (struct aaline_fragment_shader
*) fs
;
732 aaline
->driver_bind_fs_state(aaline
->pipe
, aafs
->driver_fs
);
737 aaline_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
739 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
740 struct aaline_fragment_shader
*aafs
= (struct aaline_fragment_shader
*) fs
;
742 aaline
->driver_delete_fs_state(aaline
->pipe
, aafs
->driver_fs
);
748 aaline_bind_sampler_state(struct pipe_context
*pipe
,
749 unsigned unit
, void *sampler
)
751 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
753 aaline
->state
.sampler
[unit
] = sampler
;
755 aaline
->driver_bind_sampler_state(aaline
->pipe
, unit
, sampler
);
760 aaline_set_sampler_texture(struct pipe_context
*pipe
,
761 unsigned sampler
, struct pipe_texture
*texture
)
763 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
765 aaline
->state
.texture
[sampler
] = texture
;
767 aaline
->driver_set_sampler_texture(aaline
->pipe
, sampler
, texture
);
772 * Called by drivers that want to install this AA line prim stage
773 * into the draw module's pipeline. This will not be used if the
774 * hardware has native support for AA lines.
777 draw_install_aaline_stage(struct draw_context
*draw
, struct pipe_context
*pipe
)
779 struct aaline_stage
*aaline
;
781 pipe
->draw
= (void *) draw
;
784 * Create / install AA line drawing / prim stage
786 aaline
= draw_aaline_stage( draw
);
788 draw
->pipeline
.aaline
= &aaline
->stage
;
792 /* create special texture, sampler state */
793 aaline_create_texture(aaline
);
794 aaline_create_sampler(aaline
);
796 /* save original driver functions */
797 aaline
->driver_create_fs_state
= pipe
->create_fs_state
;
798 aaline
->driver_bind_fs_state
= pipe
->bind_fs_state
;
799 aaline
->driver_delete_fs_state
= pipe
->delete_fs_state
;
801 aaline
->driver_bind_sampler_state
= pipe
->bind_sampler_state
;
802 aaline
->driver_set_sampler_texture
= pipe
->set_sampler_texture
;
804 /* override the driver's functions */
805 pipe
->create_fs_state
= aaline_create_fs_state
;
806 pipe
->bind_fs_state
= aaline_bind_fs_state
;
807 pipe
->delete_fs_state
= aaline_delete_fs_state
;
809 pipe
->bind_sampler_state
= aaline_bind_sampler_state
;
810 pipe
->set_sampler_texture
= aaline_set_sampler_texture
;