gallium: split draw_wide_prim stage into separate point/line stages.
[mesa.git] / src / gallium / auxiliary / draw / draw_pstipple.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * Polygon stipple stage: implement polygon stipple with texture map and
30 * fragment program. The fragment program samples the texture and does
31 * a fragment kill for the stipple-failing fragments.
32 *
33 * Authors: Brian Paul
34 */
35
36
37 #include "pipe/p_util.h"
38 #include "pipe/p_inlines.h"
39 #include "pipe/p_context.h"
40 #include "pipe/p_defines.h"
41 #include "pipe/p_shader_tokens.h"
42
43 #include "tgsi/util/tgsi_transform.h"
44 #include "tgsi/util/tgsi_dump.h"
45
46 #include "draw_context.h"
47 #include "draw_private.h"
48
49
50
51 /**
52 * Subclass of pipe_shader_state to carry extra fragment shader info.
53 */
54 struct pstip_fragment_shader
55 {
56 struct pipe_shader_state state;
57 void *driver_fs;
58 void *pstip_fs;
59 };
60
61
62 /**
63 * Subclass of draw_stage
64 */
65 struct pstip_stage
66 {
67 struct draw_stage stage;
68
69 void *sampler_cso;
70 struct pipe_texture *texture;
71 uint sampler_unit;
72
73 /*
74 * Currently bound state
75 */
76 struct pstip_fragment_shader *fs;
77 struct {
78 void *sampler[PIPE_MAX_SAMPLERS];
79 struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
80 const struct pipe_poly_stipple *stipple;
81 } state;
82
83 /*
84 * Driver interface/override functions
85 */
86 void * (*driver_create_fs_state)(struct pipe_context *,
87 const struct pipe_shader_state *);
88 void (*driver_bind_fs_state)(struct pipe_context *, void *);
89 void (*driver_delete_fs_state)(struct pipe_context *, void *);
90
91 void (*driver_bind_sampler_state)(struct pipe_context *, unsigned, void *);
92
93 void (*driver_set_sampler_texture)(struct pipe_context *,
94 unsigned sampler,
95 struct pipe_texture *);
96
97 void (*driver_set_polygon_stipple)(struct pipe_context *,
98 const struct pipe_poly_stipple *);
99
100 struct pipe_context *pipe;
101 };
102
103
104
105 /**
106 * Subclass of tgsi_transform_context, used for transforming the
107 * user's fragment shader to add the special AA instructions.
108 */
109 struct pstip_transform_context {
110 struct tgsi_transform_context base;
111 uint tempsUsed; /**< bitmask */
112 int wincoordInput;
113 int maxInput;
114 int maxSampler; /**< max sampler index found */
115 int texTemp; /**< temp registers */
116 int numImmed;
117 boolean firstInstruction;
118 };
119
120
121 /**
122 * TGSI declaration transform callback.
123 * Look for a free sampler, a free input attrib, and two free temp regs.
124 */
125 static void
126 pstip_transform_decl(struct tgsi_transform_context *ctx,
127 struct tgsi_full_declaration *decl)
128 {
129 struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx;
130
131 if (decl->Declaration.File == TGSI_FILE_SAMPLER) {
132 if ((int) decl->u.DeclarationRange.Last > pctx->maxSampler)
133 pctx->maxSampler = (int) decl->u.DeclarationRange.Last;
134 }
135 else if (decl->Declaration.File == TGSI_FILE_INPUT) {
136 pctx->maxInput = MAX2(pctx->maxInput, (int) decl->u.DeclarationRange.Last);
137 if (decl->Semantic.SemanticName == TGSI_SEMANTIC_POSITION)
138 pctx->wincoordInput = (int) decl->u.DeclarationRange.First;
139 }
140 else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) {
141 uint i;
142 for (i = decl->u.DeclarationRange.First;
143 i <= decl->u.DeclarationRange.Last; i++) {
144 pctx->tempsUsed |= (1 << i);
145 }
146 }
147
148 ctx->emit_declaration(ctx, decl);
149 }
150
151
152 static void
153 pstip_transform_immed(struct tgsi_transform_context *ctx,
154 struct tgsi_full_immediate *immed)
155 {
156 struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx;
157 pctx->numImmed++;
158 }
159
160
161 /**
162 * TGSI instruction transform callback.
163 * Replace writes to result.color w/ a temp reg.
164 * Upon END instruction, insert texture sampling code for antialiasing.
165 */
166 static void
167 pstip_transform_inst(struct tgsi_transform_context *ctx,
168 struct tgsi_full_instruction *inst)
169 {
170 struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx;
171
172 if (pctx->firstInstruction) {
173 /* emit our new declarations before the first instruction */
174
175 struct tgsi_full_declaration decl;
176 struct tgsi_full_instruction newInst;
177 uint i;
178 int wincoordInput;
179 const int sampler = pctx->maxSampler + 1;
180
181 if (pctx->wincoordInput < 0)
182 wincoordInput = pctx->maxInput + 1;
183 else
184 wincoordInput = pctx->wincoordInput;
185
186 /* find one free temp reg */
187 for (i = 0; i < 32; i++) {
188 if ((pctx->tempsUsed & (1 << i)) == 0) {
189 /* found a free temp */
190 if (pctx->texTemp < 0)
191 pctx->texTemp = i;
192 else
193 break;
194 }
195 }
196 assert(pctx->texTemp >= 0);
197
198 if (pctx->wincoordInput < 0) {
199 /* declare new position input reg */
200 decl = tgsi_default_full_declaration();
201 decl.Declaration.File = TGSI_FILE_INPUT;
202 decl.Declaration.Semantic = 1;
203 decl.Semantic.SemanticName = TGSI_SEMANTIC_POSITION;
204 decl.Semantic.SemanticIndex = 0;
205 decl.Declaration.Interpolate = 1;
206 decl.Interpolation.Interpolate = TGSI_INTERPOLATE_LINEAR; /* XXX? */
207 decl.u.DeclarationRange.First =
208 decl.u.DeclarationRange.Last = wincoordInput;
209 ctx->emit_declaration(ctx, &decl);
210 }
211
212 /* declare new sampler */
213 decl = tgsi_default_full_declaration();
214 decl.Declaration.File = TGSI_FILE_SAMPLER;
215 decl.u.DeclarationRange.First =
216 decl.u.DeclarationRange.Last = sampler;
217 ctx->emit_declaration(ctx, &decl);
218
219 /* declare new temp regs */
220 decl = tgsi_default_full_declaration();
221 decl.Declaration.File = TGSI_FILE_TEMPORARY;
222 decl.u.DeclarationRange.First =
223 decl.u.DeclarationRange.Last = pctx->texTemp;
224 ctx->emit_declaration(ctx, &decl);
225
226 /* emit immediate = {1/32, 1/32, 1, 1}
227 * The index/position of this immediate will be pctx->numImmed
228 */
229 {
230 static const float value[4] = { 1.0/32, 1.0/32, 1.0, 1.0 };
231 struct tgsi_full_immediate immed;
232 uint size = 4;
233 immed = tgsi_default_full_immediate();
234 immed.Immediate.Size = 1 + size; /* one for the token itself */
235 immed.u.ImmediateFloat32 = (struct tgsi_immediate_float32 *) value;
236 ctx->emit_immediate(ctx, &immed);
237 }
238
239 pctx->firstInstruction = FALSE;
240
241
242 /*
243 * Insert new MUL/TEX/KILP instructions at start of program
244 * Take gl_FragCoord, divide by 32 (stipple size), sample the
245 * texture and kill fragment if needed.
246 *
247 * We'd like to use non-normalized texcoords to index into a RECT
248 * texture, but we can only use GL_REPEAT wrap mode with normalized
249 * texcoords. Darn.
250 */
251
252 /* MUL texTemp, INPUT[wincoord], 1/32; */
253 newInst = tgsi_default_full_instruction();
254 newInst.Instruction.Opcode = TGSI_OPCODE_MUL;
255 newInst.Instruction.NumDstRegs = 1;
256 newInst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_TEMPORARY;
257 newInst.FullDstRegisters[0].DstRegister.Index = pctx->texTemp;
258 newInst.Instruction.NumSrcRegs = 2;
259 newInst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
260 newInst.FullSrcRegisters[0].SrcRegister.Index = wincoordInput;
261 newInst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_IMMEDIATE;
262 newInst.FullSrcRegisters[1].SrcRegister.Index = pctx->numImmed;
263 ctx->emit_instruction(ctx, &newInst);
264
265 /* TEX texTemp, texTemp, sampler; */
266 newInst = tgsi_default_full_instruction();
267 newInst.Instruction.Opcode = TGSI_OPCODE_TEX;
268 newInst.Instruction.NumDstRegs = 1;
269 newInst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_TEMPORARY;
270 newInst.FullDstRegisters[0].DstRegister.Index = pctx->texTemp;
271 newInst.Instruction.NumSrcRegs = 2;
272 newInst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D;
273 newInst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_TEMPORARY;
274 newInst.FullSrcRegisters[0].SrcRegister.Index = pctx->texTemp;
275 newInst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
276 newInst.FullSrcRegisters[1].SrcRegister.Index = sampler;
277 ctx->emit_instruction(ctx, &newInst);
278
279 /* KILP texTemp; # if texTemp < 0, KILL fragment */
280 newInst = tgsi_default_full_instruction();
281 newInst.Instruction.Opcode = TGSI_OPCODE_KILP;
282 newInst.Instruction.NumDstRegs = 0;
283 newInst.Instruction.NumSrcRegs = 1;
284 newInst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_TEMPORARY;
285 newInst.FullSrcRegisters[0].SrcRegister.Index = pctx->texTemp;
286 newInst.FullSrcRegisters[0].SrcRegister.Negate = 1;
287 ctx->emit_instruction(ctx, &newInst);
288 }
289
290 /* emit this instruction */
291 ctx->emit_instruction(ctx, inst);
292 }
293
294
295 /**
296 * Generate the frag shader we'll use for doing polygon stipple.
297 * This will be the user's shader prefixed with a TEX and KIL instruction.
298 */
299 static void
300 generate_pstip_fs(struct pstip_stage *pstip)
301 {
302 const struct pipe_shader_state *orig_fs = &pstip->fs->state;
303 /*struct draw_context *draw = pstip->stage.draw;*/
304 struct pipe_shader_state pstip_fs;
305 struct pstip_transform_context transform;
306
307 #define MAX 1000
308
309 pstip_fs = *orig_fs; /* copy to init */
310 pstip_fs.tokens = MALLOC(sizeof(struct tgsi_token) * MAX);
311
312 memset(&transform, 0, sizeof(transform));
313 transform.wincoordInput = -1;
314 transform.maxInput = -1;
315 transform.maxSampler = -1;
316 transform.texTemp = -1;
317 transform.firstInstruction = TRUE;
318 transform.base.transform_instruction = pstip_transform_inst;
319 transform.base.transform_declaration = pstip_transform_decl;
320 transform.base.transform_immediate = pstip_transform_immed;
321
322 tgsi_transform_shader(orig_fs->tokens,
323 (struct tgsi_token *) pstip_fs.tokens,
324 MAX, &transform.base);
325
326 #if 1 /* DEBUG */
327 tgsi_dump(orig_fs->tokens, 0);
328 tgsi_dump(pstip_fs.tokens, 0);
329 #endif
330
331 pstip->sampler_unit = transform.maxSampler + 1;
332
333 #if 1 /* XXX remove */
334 if (transform.wincoordInput < 0) {
335 pstip_fs.input_semantic_name[pstip_fs.num_inputs] = TGSI_SEMANTIC_POSITION;
336 pstip_fs.input_semantic_index[pstip_fs.num_inputs] = (ubyte)transform.maxInput;
337 pstip_fs.num_inputs++;
338 }
339 #endif
340
341 pstip->fs->pstip_fs = pstip->driver_create_fs_state(pstip->pipe, &pstip_fs);
342 }
343
344
345 /**
346 * Load texture image with current stipple pattern.
347 */
348 static void
349 pstip_update_texture(struct pstip_stage *pstip)
350 {
351 static const uint bit31 = 1 << 31;
352 struct pipe_context *pipe = pstip->pipe;
353 struct pipe_screen *screen = pipe->screen;
354 struct pipe_surface *surface;
355 const uint *stipple = pstip->state.stipple->stipple;
356 uint i, j;
357 ubyte *data;
358
359 surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0);
360 data = pipe_surface_map(surface);
361
362 /*
363 * Load alpha texture.
364 * Note: 0 means keep the fragment, 255 means kill it.
365 * We'll negate the texel value and use KILP which kills if value
366 * is negative.
367 */
368 for (i = 0; i < 32; i++) {
369 for (j = 0; j < 32; j++) {
370 if (stipple[i] & (bit31 >> j)) {
371 /* fragment "on" */
372 data[i * surface->pitch + j] = 0;
373 }
374 else {
375 /* fragment "off" */
376 data[i * surface->pitch + j] = 255;
377 }
378 }
379 }
380
381 /* unmap */
382 pipe_surface_unmap(surface);
383 pipe_surface_reference(&surface, NULL);
384 pipe->texture_update(pipe, pstip->texture);
385 }
386
387
388 /**
389 * Create the texture map we'll use for stippling.
390 */
391 static void
392 pstip_create_texture(struct pstip_stage *pstip)
393 {
394 struct pipe_context *pipe = pstip->pipe;
395 struct pipe_screen *screen = pipe->screen;
396 struct pipe_texture texTemp;
397
398 memset(&texTemp, 0, sizeof(texTemp));
399 texTemp.target = PIPE_TEXTURE_2D;
400 texTemp.format = PIPE_FORMAT_U_A8; /* XXX verify supported by driver! */
401 texTemp.last_level = 0;
402 texTemp.width[0] = 32;
403 texTemp.height[0] = 32;
404 texTemp.depth[0] = 1;
405 texTemp.cpp = 1;
406
407 pstip->texture = screen->texture_create(screen, &texTemp);
408
409 //pstip_update_texture(pstip);
410 }
411
412
413 /**
414 * Create the sampler CSO that'll be used for antialiasing.
415 * By using a mipmapped texture, we don't have to generate a different
416 * texture image for each line size.
417 */
418 static void
419 pstip_create_sampler(struct pstip_stage *pstip)
420 {
421 struct pipe_sampler_state sampler;
422 struct pipe_context *pipe = pstip->pipe;
423
424 memset(&sampler, 0, sizeof(sampler));
425 sampler.wrap_s = PIPE_TEX_WRAP_REPEAT;
426 sampler.wrap_t = PIPE_TEX_WRAP_REPEAT;
427 sampler.wrap_r = PIPE_TEX_WRAP_REPEAT;
428 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
429 sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
430 sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
431 sampler.normalized_coords = 1;
432 sampler.min_lod = 0.0f;
433 sampler.max_lod = 0.0f;
434
435 pstip->sampler_cso = pipe->create_sampler_state(pipe, &sampler);
436 }
437
438
439 /**
440 * When we're about to draw our first AA line in a batch, this function is
441 * called to tell the driver to bind our modified fragment shader.
442 */
443 static void
444 bind_pstip_fragment_shader(struct pstip_stage *pstip)
445 {
446 if (!pstip->fs->pstip_fs) {
447 generate_pstip_fs(pstip);
448 }
449 pstip->driver_bind_fs_state(pstip->pipe, pstip->fs->pstip_fs);
450 }
451
452
453
454 static INLINE struct pstip_stage *
455 pstip_stage( struct draw_stage *stage )
456 {
457 return (struct pstip_stage *) stage;
458 }
459
460
461 static void
462 passthrough_point(struct draw_stage *stage, struct prim_header *header)
463 {
464 stage->next->point(stage->next, header);
465 }
466
467
468 static void
469 passthrough_line(struct draw_stage *stage, struct prim_header *header)
470 {
471 stage->next->line(stage->next, header);
472 }
473
474
475 static void
476 passthrough_tri(struct draw_stage *stage, struct prim_header *header)
477 {
478 stage->next->tri(stage->next, header);
479 }
480
481
482
483 static void
484 pstip_first_tri(struct draw_stage *stage, struct prim_header *header)
485 {
486 struct pstip_stage *pstip = pstip_stage(stage);
487 struct draw_context *draw = stage->draw;
488 struct pipe_context *pipe = pstip->pipe;
489
490 assert(draw->rasterizer->poly_stipple_enable);
491
492 /*
493 * Bind our fragprog, sampler and texture
494 */
495 bind_pstip_fragment_shader(pstip);
496
497 pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit, pstip->sampler_cso);
498 pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit, pstip->texture);
499
500 /* now really draw first line */
501 stage->tri = passthrough_tri;
502 stage->tri(stage, header);
503 }
504
505
506 static void
507 pstip_flush(struct draw_stage *stage, unsigned flags)
508 {
509 /*struct draw_context *draw = stage->draw;*/
510 struct pstip_stage *pstip = pstip_stage(stage);
511 struct pipe_context *pipe = pstip->pipe;
512
513 stage->tri = pstip_first_tri;
514 stage->next->flush( stage->next, flags );
515
516 /* restore original frag shader */
517 pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs);
518
519 /* XXX restore original texture, sampler state */
520 pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit,
521 pstip->state.sampler[pstip->sampler_unit]);
522 pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit,
523 pstip->state.texture[pstip->sampler_unit]);
524 }
525
526
527 static void
528 pstip_reset_stipple_counter(struct draw_stage *stage)
529 {
530 stage->next->reset_stipple_counter( stage->next );
531 }
532
533
534 static void
535 pstip_destroy(struct draw_stage *stage)
536 {
537 draw_free_temp_verts( stage );
538 FREE( stage );
539 }
540
541
542 static struct pstip_stage *
543 draw_pstip_stage(struct draw_context *draw)
544 {
545 struct pstip_stage *pstip = CALLOC_STRUCT(pstip_stage);
546
547 draw_alloc_temp_verts( &pstip->stage, 8 );
548
549 pstip->stage.draw = draw;
550 pstip->stage.next = NULL;
551 pstip->stage.point = passthrough_point;
552 pstip->stage.line = passthrough_line;
553 pstip->stage.tri = pstip_first_tri;
554 pstip->stage.flush = pstip_flush;
555 pstip->stage.reset_stipple_counter = pstip_reset_stipple_counter;
556 pstip->stage.destroy = pstip_destroy;
557
558 return pstip;
559 }
560
561
562 /*
563 * XXX temporary? solution to mapping a pipe_context to a pstip_stage.
564 */
565
566 #define MAX_CONTEXTS 10
567
568 static struct pipe_context *Pipe[MAX_CONTEXTS];
569 static struct pstip_stage *Stage[MAX_CONTEXTS];
570 static uint NumContexts;
571
572 static void
573 add_pstip_pipe_context(struct pipe_context *pipe, struct pstip_stage *pstip)
574 {
575 assert(NumContexts < MAX_CONTEXTS);
576 Pipe[NumContexts] = pipe;
577 Stage[NumContexts] = pstip;
578 NumContexts++;
579 }
580
581 static struct pstip_stage *
582 pstip_stage_from_pipe(struct pipe_context *pipe)
583 {
584 uint i;
585 for (i = 0; i < NumContexts; i++) {
586 if (Pipe[i] == pipe)
587 return Stage[i];
588 }
589 assert(0);
590 return NULL;
591 }
592
593
594 /**
595 * This function overrides the driver's create_fs_state() function and
596 * will typically be called by the state tracker.
597 */
598 static void *
599 pstip_create_fs_state(struct pipe_context *pipe,
600 const struct pipe_shader_state *fs)
601 {
602 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
603 struct pstip_fragment_shader *aafs = CALLOC_STRUCT(pstip_fragment_shader);
604
605 if (aafs) {
606 aafs->state = *fs;
607
608 /* pass-through */
609 aafs->driver_fs = pstip->driver_create_fs_state(pstip->pipe, fs);
610 }
611
612 return aafs;
613 }
614
615
616 static void
617 pstip_bind_fs_state(struct pipe_context *pipe, void *fs)
618 {
619 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
620 struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs;
621 /* save current */
622 pstip->fs = aafs;
623 /* pass-through */
624 pstip->driver_bind_fs_state(pstip->pipe, aafs->driver_fs);
625 }
626
627
628 static void
629 pstip_delete_fs_state(struct pipe_context *pipe, void *fs)
630 {
631 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
632 struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs;
633 /* pass-through */
634 pstip->driver_delete_fs_state(pstip->pipe, aafs->driver_fs);
635 FREE(aafs);
636 }
637
638
639 static void
640 pstip_bind_sampler_state(struct pipe_context *pipe,
641 unsigned unit, void *sampler)
642 {
643 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
644 /* save current */
645 pstip->state.sampler[unit] = sampler;
646 /* pass-through */
647 pstip->driver_bind_sampler_state(pstip->pipe, unit, sampler);
648 }
649
650
651 static void
652 pstip_set_sampler_texture(struct pipe_context *pipe,
653 unsigned sampler, struct pipe_texture *texture)
654 {
655 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
656 /* save current */
657 pstip->state.texture[sampler] = texture;
658 /* pass-through */
659 pstip->driver_set_sampler_texture(pstip->pipe, sampler, texture);
660 }
661
662
663 static void
664 pstip_set_polygon_stipple(struct pipe_context *pipe,
665 const struct pipe_poly_stipple *stipple)
666 {
667 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
668 /* save current */
669 pstip->state.stipple = stipple;
670 /* pass-through */
671 pstip->driver_set_polygon_stipple(pstip->pipe, stipple);
672
673 pstip_update_texture(pstip);
674 }
675
676
677
678 /**
679 * Called by drivers that want to install this AA line prim stage
680 * into the draw module's pipeline. This will not be used if the
681 * hardware has native support for AA lines.
682 */
683 void
684 draw_install_pstipple_stage(struct draw_context *draw,
685 struct pipe_context *pipe)
686 {
687 struct pstip_stage *pstip;
688
689 /*
690 * Create / install AA line drawing / prim stage
691 */
692 pstip = draw_pstip_stage( draw );
693 assert(pstip);
694 draw->pipeline.pstipple = &pstip->stage;
695
696 pstip->pipe = pipe;
697
698 /* create special texture, sampler state */
699 pstip_create_texture(pstip);
700 pstip_create_sampler(pstip);
701
702 /* save original driver functions */
703 pstip->driver_create_fs_state = pipe->create_fs_state;
704 pstip->driver_bind_fs_state = pipe->bind_fs_state;
705 pstip->driver_delete_fs_state = pipe->delete_fs_state;
706
707 pstip->driver_bind_sampler_state = pipe->bind_sampler_state;
708 pstip->driver_set_sampler_texture = pipe->set_sampler_texture;
709 pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple;
710
711 /* override the driver's functions */
712 pipe->create_fs_state = pstip_create_fs_state;
713 pipe->bind_fs_state = pstip_bind_fs_state;
714 pipe->delete_fs_state = pstip_delete_fs_state;
715
716 pipe->bind_sampler_state = pstip_bind_sampler_state;
717 pipe->set_sampler_texture = pstip_set_sampler_texture;
718 pipe->set_polygon_stipple = pstip_set_polygon_stipple;
719
720 add_pstip_pipe_context(pipe, pstip);
721 }