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 aaline_fs
.input_semantic_name
[aaline_fs
.num_inputs
] = TGSI_SEMANTIC_GENERIC
;
344 aaline_fs
.input_semantic_index
[aaline_fs
.num_inputs
] = transform
.maxGeneric
+ 1;
345 aaline_fs
.num_inputs
++;
347 aaline
->fs
->aaline_fs
348 = aaline
->driver_create_fs_state(aaline
->pipe
, &aaline_fs
);
350 /* advertise the extra post-transform vertex attributes which will have
353 draw
->extra_vp_outputs
.semantic_name
= TGSI_SEMANTIC_GENERIC
;
354 draw
->extra_vp_outputs
.semantic_index
= transform
.maxGeneric
+ 1;
359 * Create the texture map we'll use for antialiasing the lines.
362 aaline_create_texture(struct aaline_stage
*aaline
)
364 struct pipe_context
*pipe
= aaline
->pipe
;
365 struct pipe_texture texTemp
;
368 memset(&texTemp
, 0, sizeof(texTemp
));
369 texTemp
.target
= PIPE_TEXTURE_2D
;
370 texTemp
.format
= PIPE_FORMAT_U_A8
; /* XXX verify supported by driver! */
371 texTemp
.last_level
= MAX_TEXTURE_LEVEL
;
372 texTemp
.width
[0] = 1 << MAX_TEXTURE_LEVEL
;
373 texTemp
.height
[0] = 1 << MAX_TEXTURE_LEVEL
;
374 texTemp
.depth
[0] = 1;
377 aaline
->texture
= pipe
->texture_create(pipe
, &texTemp
);
379 /* Fill in mipmap images.
380 * Basically each level is solid opaque, except for the outermost
381 * texels which are zero. Special case the 1x1 and 2x2 levels.
383 for (level
= 0; level
<= MAX_TEXTURE_LEVEL
; level
++) {
384 struct pipe_surface
*surface
;
385 const uint size
= aaline
->texture
->width
[level
];
389 assert(aaline
->texture
->width
[level
] == aaline
->texture
->height
[level
]);
391 surface
= pipe
->get_tex_surface(pipe
, aaline
->texture
, 0, level
, 0);
392 data
= pipe_surface_map(surface
);
394 for (i
= 0; i
< size
; i
++) {
395 for (j
= 0; j
< size
; j
++) {
400 else if (size
== 2) {
401 d
= 200; /* tuneable */
403 else if (i
== 0 || j
== 0 || i
== size
- 1 || j
== size
- 1) {
409 data
[i
* surface
->pitch
+ j
] = d
;
414 pipe_surface_unmap(surface
);
415 pipe_surface_reference(&surface
, NULL
);
421 * Create the sampler CSO that'll be used for antialiasing.
422 * By using a mipmapped texture, we don't have to generate a different
423 * texture image for each line size.
426 aaline_create_sampler(struct aaline_stage
*aaline
)
428 struct pipe_sampler_state sampler
;
429 struct pipe_context
*pipe
= aaline
->pipe
;
431 memset(&sampler
, 0, sizeof(sampler
));
432 sampler
.wrap_s
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
433 sampler
.wrap_t
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
434 sampler
.wrap_r
= PIPE_TEX_WRAP_CLAMP_TO_EDGE
;
435 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_LINEAR
;
436 sampler
.min_img_filter
= PIPE_TEX_FILTER_LINEAR
;
437 sampler
.mag_img_filter
= PIPE_TEX_FILTER_LINEAR
;
438 sampler
.normalized_coords
= 1;
439 sampler
.min_lod
= 0.0f
;
440 sampler
.max_lod
= MAX_TEXTURE_LEVEL
;
442 aaline
->sampler_cso
= pipe
->create_sampler_state(pipe
, &sampler
);
447 * When we're about to draw our first AA line in a batch, this function is
448 * called to tell the driver to bind our modified fragment shader.
451 bind_aaline_fragment_shader(struct aaline_stage
*aaline
)
453 if (!aaline
->fs
->aaline_fs
) {
454 generate_aaline_fs(aaline
);
456 aaline
->driver_bind_fs_state(aaline
->pipe
, aaline
->fs
->aaline_fs
);
461 static INLINE
struct aaline_stage
*
462 aaline_stage( struct draw_stage
*stage
)
464 return (struct aaline_stage
*) stage
;
469 passthrough_point(struct draw_stage
*stage
, struct prim_header
*header
)
471 stage
->next
->point(stage
->next
, header
);
476 passthrough_tri(struct draw_stage
*stage
, struct prim_header
*header
)
478 stage
->next
->tri(stage
->next
, header
);
483 * Draw a wide line by drawing a quad, using geometry which will
484 * fullfill GL's antialiased line requirements.
487 aaline_line(struct draw_stage
*stage
, struct prim_header
*header
)
489 const struct aaline_stage
*aaline
= aaline_stage(stage
);
490 const float half_width
= aaline
->half_line_width
;
491 struct prim_header tri
;
492 struct vertex_header
*v
[8];
493 uint texPos
= aaline
->tex_slot
;
495 float dx
= header
->v
[1]->data
[0][0] - header
->v
[0]->data
[0][0];
496 float dy
= header
->v
[1]->data
[0][1] - header
->v
[0]->data
[0][1];
497 double a
= atan2(dy
, dx
);
498 float c_a
= (float) cos(a
), s_a
= (float) sin(a
);
501 /* XXX the ends of lines aren't quite perfect yet, but probably passable */
502 dx
= 0.5F
* half_width
;
505 /* allocate/dup new verts */
506 for (i
= 0; i
< 8; i
++) {
507 v
[i
] = dup_vert(stage
, header
->v
[i
/4], i
);
511 * Quad strip for line from v0 to v1 (*=endpoints):
514 * +---+---------------------+---+
518 * +---+---------------------+---+
524 pos
[0] += (-dx
* c_a
- dy
* s_a
);
525 pos
[1] += (-dx
* s_a
+ dy
* c_a
);
528 pos
[0] += (-dx
* c_a
- -dy
* s_a
);
529 pos
[1] += (-dx
* s_a
+ -dy
* c_a
);
532 pos
[0] += ( dx
* c_a
- dy
* s_a
);
533 pos
[1] += ( dx
* s_a
+ dy
* c_a
);
536 pos
[0] += ( dx
* c_a
- -dy
* s_a
);
537 pos
[1] += ( dx
* s_a
+ -dy
* c_a
);
540 pos
[0] += (-dx
* c_a
- dy
* s_a
);
541 pos
[1] += (-dx
* s_a
+ dy
* c_a
);
544 pos
[0] += (-dx
* c_a
- -dy
* s_a
);
545 pos
[1] += (-dx
* s_a
+ -dy
* c_a
);
548 pos
[0] += ( dx
* c_a
- dy
* s_a
);
549 pos
[1] += ( dx
* s_a
+ dy
* c_a
);
552 pos
[0] += ( dx
* c_a
- -dy
* s_a
);
553 pos
[1] += ( dx
* s_a
+ -dy
* c_a
);
556 tex
= v
[0]->data
[texPos
];
557 ASSIGN_4V(tex
, 0, 0, 0, 1);
559 tex
= v
[1]->data
[texPos
];
560 ASSIGN_4V(tex
, 0, 1, 0, 1);
562 tex
= v
[2]->data
[texPos
];
563 ASSIGN_4V(tex
, .5, 0, 0, 1);
565 tex
= v
[3]->data
[texPos
];
566 ASSIGN_4V(tex
, .5, 1, 0, 1);
568 tex
= v
[4]->data
[texPos
];
569 ASSIGN_4V(tex
, .5, 0, 0, 1);
571 tex
= v
[5]->data
[texPos
];
572 ASSIGN_4V(tex
, .5, 1, 0, 1);
574 tex
= v
[6]->data
[texPos
];
575 ASSIGN_4V(tex
, 1, 0, 0, 1);
577 tex
= v
[7]->data
[texPos
];
578 ASSIGN_4V(tex
, 1, 1, 0, 1);
580 /* emit 6 tris for the quad strip */
581 tri
.v
[0] = v
[2]; tri
.v
[1] = v
[1]; tri
.v
[2] = v
[0];
582 stage
->next
->tri( stage
->next
, &tri
);
584 tri
.v
[0] = v
[3]; tri
.v
[1] = v
[1]; tri
.v
[2] = v
[2];
585 stage
->next
->tri( stage
->next
, &tri
);
587 tri
.v
[0] = v
[4]; tri
.v
[1] = v
[3]; tri
.v
[2] = v
[2];
588 stage
->next
->tri( stage
->next
, &tri
);
590 tri
.v
[0] = v
[5]; tri
.v
[1] = v
[3]; tri
.v
[2] = v
[4];
591 stage
->next
->tri( stage
->next
, &tri
);
593 tri
.v
[0] = v
[6]; tri
.v
[1] = v
[5]; tri
.v
[2] = v
[4];
594 stage
->next
->tri( stage
->next
, &tri
);
596 tri
.v
[0] = v
[7]; tri
.v
[1] = v
[5]; tri
.v
[2] = v
[6];
597 stage
->next
->tri( stage
->next
, &tri
);
602 aaline_first_line(struct draw_stage
*stage
, struct prim_header
*header
)
604 auto struct aaline_stage
*aaline
= aaline_stage(stage
);
605 struct draw_context
*draw
= stage
->draw
;
606 struct pipe_context
*pipe
= aaline
->pipe
;
608 assert(draw
->rasterizer
->line_smooth
);
610 if (draw
->rasterizer
->line_width
<= 3.0)
611 aaline
->half_line_width
= 1.5f
;
613 aaline
->half_line_width
= 0.5f
* draw
->rasterizer
->line_width
;
615 aaline
->tex_slot
= draw
->num_vs_outputs
;
616 assert(aaline
->tex_slot
> 0); /* output[0] is vertex pos */
617 draw
->extra_vp_outputs
.slot
= aaline
->tex_slot
;
620 * Bind our fragprog, sampler and texture
622 bind_aaline_fragment_shader(aaline
);
624 aaline
->driver_bind_sampler_state(pipe
, aaline
->sampler_unit
, aaline
->sampler_cso
);
625 aaline
->driver_set_sampler_texture(pipe
, aaline
->sampler_unit
, aaline
->texture
);
627 /* now really draw first line */
628 stage
->line
= aaline_line
;
629 stage
->line(stage
, header
);
634 aaline_flush(struct draw_stage
*stage
, unsigned flags
)
636 struct draw_context
*draw
= stage
->draw
;
637 struct aaline_stage
*aaline
= aaline_stage(stage
);
638 struct pipe_context
*pipe
= aaline
->pipe
;
640 stage
->line
= aaline_first_line
;
641 stage
->next
->flush( stage
->next
, flags
);
643 /* restore original frag shader */
644 aaline
->driver_bind_fs_state(pipe
, aaline
->fs
->driver_fs
);
646 /* XXX restore original texture, sampler state */
647 aaline
->driver_bind_sampler_state(pipe
, aaline
->sampler_unit
,
648 aaline
->state
.sampler
[aaline
->sampler_unit
]);
649 aaline
->driver_set_sampler_texture(pipe
, aaline
->sampler_unit
,
650 aaline
->state
.texture
[aaline
->sampler_unit
]);
652 draw
->extra_vp_outputs
.slot
= 0;
657 aaline_reset_stipple_counter(struct draw_stage
*stage
)
659 stage
->next
->reset_stipple_counter( stage
->next
);
664 aaline_destroy(struct draw_stage
*stage
)
666 draw_free_temp_verts( stage
);
671 static struct aaline_stage
*
672 draw_aaline_stage(struct draw_context
*draw
)
674 struct aaline_stage
*aaline
= CALLOC_STRUCT(aaline_stage
);
676 draw_alloc_temp_verts( &aaline
->stage
, 8 );
678 aaline
->stage
.draw
= draw
;
679 aaline
->stage
.next
= NULL
;
680 aaline
->stage
.point
= passthrough_point
;
681 aaline
->stage
.line
= aaline_first_line
;
682 aaline
->stage
.tri
= passthrough_tri
;
683 aaline
->stage
.flush
= aaline_flush
;
684 aaline
->stage
.reset_stipple_counter
= aaline_reset_stipple_counter
;
685 aaline
->stage
.destroy
= aaline_destroy
;
692 * XXX temporary? solution to mapping a pipe_context to a aaline_stage.
695 #define MAX_CONTEXTS 10
697 static struct pipe_context
*Pipe
[MAX_CONTEXTS
];
698 static struct aaline_stage
*Stage
[MAX_CONTEXTS
];
699 static uint NumContexts
;
702 add_aa_pipe_context(struct pipe_context
*pipe
, struct aaline_stage
*aa
)
704 assert(NumContexts
< MAX_CONTEXTS
);
705 Pipe
[NumContexts
] = pipe
;
706 Stage
[NumContexts
] = aa
;
710 static struct aaline_stage
*
711 aaline_stage_from_pipe(struct pipe_context
*pipe
)
714 for (i
= 0; i
< NumContexts
; i
++) {
724 * This function overrides the driver's create_fs_state() function and
725 * will typically be called by the state tracker.
728 aaline_create_fs_state(struct pipe_context
*pipe
,
729 const struct pipe_shader_state
*fs
)
731 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
732 struct aaline_fragment_shader
*aafs
= CALLOC_STRUCT(aaline_fragment_shader
);
738 aafs
->driver_fs
= aaline
->driver_create_fs_state(aaline
->pipe
, fs
);
746 aaline_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
748 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
749 struct aaline_fragment_shader
*aafs
= (struct aaline_fragment_shader
*) fs
;
753 aaline
->driver_bind_fs_state(aaline
->pipe
, aafs
->driver_fs
);
758 aaline_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
760 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
761 struct aaline_fragment_shader
*aafs
= (struct aaline_fragment_shader
*) fs
;
763 aaline
->driver_delete_fs_state(aaline
->pipe
, aafs
->driver_fs
);
769 aaline_bind_sampler_state(struct pipe_context
*pipe
,
770 unsigned unit
, void *sampler
)
772 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
774 aaline
->state
.sampler
[unit
] = sampler
;
776 aaline
->driver_bind_sampler_state(aaline
->pipe
, unit
, sampler
);
781 aaline_set_sampler_texture(struct pipe_context
*pipe
,
782 unsigned sampler
, struct pipe_texture
*texture
)
784 struct aaline_stage
*aaline
= aaline_stage_from_pipe(pipe
);
786 aaline
->state
.texture
[sampler
] = texture
;
788 aaline
->driver_set_sampler_texture(aaline
->pipe
, sampler
, texture
);
793 * Called by drivers that want to install this AA line prim stage
794 * into the draw module's pipeline. This will not be used if the
795 * hardware has native support for AA lines.
798 draw_install_aaline_stage(struct draw_context
*draw
, struct pipe_context
*pipe
)
800 struct aaline_stage
*aaline
;
803 * Create / install AA line drawing / prim stage
805 aaline
= draw_aaline_stage( draw
);
807 draw
->pipeline
.aaline
= &aaline
->stage
;
811 /* create special texture, sampler state */
812 aaline_create_texture(aaline
);
813 aaline_create_sampler(aaline
);
815 /* save original driver functions */
816 aaline
->driver_create_fs_state
= pipe
->create_fs_state
;
817 aaline
->driver_bind_fs_state
= pipe
->bind_fs_state
;
818 aaline
->driver_delete_fs_state
= pipe
->delete_fs_state
;
820 aaline
->driver_bind_sampler_state
= pipe
->bind_sampler_state
;
821 aaline
->driver_set_sampler_texture
= pipe
->set_sampler_texture
;
823 /* override the driver's functions */
824 pipe
->create_fs_state
= aaline_create_fs_state
;
825 pipe
->bind_fs_state
= aaline_bind_fs_state
;
826 pipe
->delete_fs_state
= aaline_delete_fs_state
;
828 pipe
->bind_sampler_state
= aaline_bind_sampler_state
;
829 pipe
->set_sampler_texture
= aaline_set_sampler_texture
;
831 add_aa_pipe_context(pipe
, aaline
);