gallium: fix bad ptr assignment
[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 (transform.wincoordInput < 0) {
334 pstip_fs.input_semantic_name[pstip_fs.num_inputs] = TGSI_SEMANTIC_POSITION;
335 pstip_fs.input_semantic_index[pstip_fs.num_inputs] = (ubyte)transform.maxInput;
336 pstip_fs.num_inputs++;
337 }
338
339 pstip->fs->pstip_fs = pstip->driver_create_fs_state(pstip->pipe, &pstip_fs);
340 }
341
342
343 /**
344 * Load texture image with current stipple pattern.
345 */
346 static void
347 pstip_update_texture(struct pstip_stage *pstip)
348 {
349 static const uint bit31 = 1 << 31;
350 struct pipe_context *pipe = pstip->pipe;
351 struct pipe_surface *surface;
352 const uint *stipple = pstip->state.stipple->stipple;
353 uint i, j;
354 ubyte *data;
355
356 surface = pipe->get_tex_surface(pipe, pstip->texture, 0, 0, 0);
357 data = pipe_surface_map(surface);
358
359 /*
360 * Load alpha texture.
361 * Note: 0 means keep the fragment, 255 means kill it.
362 * We'll negate the texel value and use KILP which kills if value
363 * is negative.
364 */
365 for (i = 0; i < 32; i++) {
366 for (j = 0; j < 32; j++) {
367 if (stipple[i] & (bit31 >> j)) {
368 /* fragment "on" */
369 data[i * surface->pitch + j] = 0;
370 }
371 else {
372 /* fragment "off" */
373 data[i * surface->pitch + j] = 255;
374 }
375 }
376 }
377
378 /* unmap */
379 pipe_surface_unmap(surface);
380 pipe_surface_reference(&surface, NULL);
381 pipe->texture_update(pipe, pstip->texture);
382 }
383
384
385 /**
386 * Create the texture map we'll use for stippling.
387 */
388 static void
389 pstip_create_texture(struct pstip_stage *pstip)
390 {
391 struct pipe_context *pipe = pstip->pipe;
392 struct pipe_texture texTemp;
393
394 memset(&texTemp, 0, sizeof(texTemp));
395 texTemp.target = PIPE_TEXTURE_2D;
396 texTemp.format = PIPE_FORMAT_U_A8; /* XXX verify supported by driver! */
397 texTemp.last_level = 0;
398 texTemp.width[0] = 32;
399 texTemp.height[0] = 32;
400 texTemp.depth[0] = 1;
401 texTemp.cpp = 1;
402
403 pstip->texture = pipe->texture_create(pipe, &texTemp);
404
405 //pstip_update_texture(pstip);
406 }
407
408
409 /**
410 * Create the sampler CSO that'll be used for antialiasing.
411 * By using a mipmapped texture, we don't have to generate a different
412 * texture image for each line size.
413 */
414 static void
415 pstip_create_sampler(struct pstip_stage *pstip)
416 {
417 struct pipe_sampler_state sampler;
418 struct pipe_context *pipe = pstip->pipe;
419
420 memset(&sampler, 0, sizeof(sampler));
421 sampler.wrap_s = PIPE_TEX_WRAP_REPEAT;
422 sampler.wrap_t = PIPE_TEX_WRAP_REPEAT;
423 sampler.wrap_r = PIPE_TEX_WRAP_REPEAT;
424 sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
425 sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST;
426 sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
427 sampler.normalized_coords = 1;
428 sampler.min_lod = 0.0f;
429 sampler.max_lod = 0.0f;
430
431 pstip->sampler_cso = pipe->create_sampler_state(pipe, &sampler);
432 }
433
434
435 /**
436 * When we're about to draw our first AA line in a batch, this function is
437 * called to tell the driver to bind our modified fragment shader.
438 */
439 static void
440 bind_pstip_fragment_shader(struct pstip_stage *pstip)
441 {
442 if (!pstip->fs->pstip_fs) {
443 generate_pstip_fs(pstip);
444 }
445 pstip->driver_bind_fs_state(pstip->pipe, pstip->fs->pstip_fs);
446 }
447
448
449
450 static INLINE struct pstip_stage *
451 pstip_stage( struct draw_stage *stage )
452 {
453 return (struct pstip_stage *) stage;
454 }
455
456
457 static void
458 passthrough_point(struct draw_stage *stage, struct prim_header *header)
459 {
460 stage->next->point(stage->next, header);
461 }
462
463
464 static void
465 passthrough_line(struct draw_stage *stage, struct prim_header *header)
466 {
467 stage->next->line(stage->next, header);
468 }
469
470
471 static void
472 passthrough_tri(struct draw_stage *stage, struct prim_header *header)
473 {
474 stage->next->tri(stage->next, header);
475 }
476
477
478
479 static void
480 pstip_first_tri(struct draw_stage *stage, struct prim_header *header)
481 {
482 struct pstip_stage *pstip = pstip_stage(stage);
483 struct draw_context *draw = stage->draw;
484 struct pipe_context *pipe = pstip->pipe;
485
486 assert(draw->rasterizer->poly_stipple_enable);
487
488 /*
489 * Bind our fragprog, sampler and texture
490 */
491 bind_pstip_fragment_shader(pstip);
492
493 pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit, pstip->sampler_cso);
494 pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit, pstip->texture);
495
496 /* now really draw first line */
497 stage->tri = passthrough_tri;
498 stage->tri(stage, header);
499 }
500
501
502 static void
503 pstip_flush(struct draw_stage *stage, unsigned flags)
504 {
505 /*struct draw_context *draw = stage->draw;*/
506 struct pstip_stage *pstip = pstip_stage(stage);
507 struct pipe_context *pipe = pstip->pipe;
508
509 stage->tri = pstip_first_tri;
510 stage->next->flush( stage->next, flags );
511
512 /* restore original frag shader */
513 pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs);
514
515 /* XXX restore original texture, sampler state */
516 pstip->driver_bind_sampler_state(pipe, pstip->sampler_unit,
517 pstip->state.sampler[pstip->sampler_unit]);
518 pstip->driver_set_sampler_texture(pipe, pstip->sampler_unit,
519 pstip->state.texture[pstip->sampler_unit]);
520 }
521
522
523 static void
524 pstip_reset_stipple_counter(struct draw_stage *stage)
525 {
526 stage->next->reset_stipple_counter( stage->next );
527 }
528
529
530 static void
531 pstip_destroy(struct draw_stage *stage)
532 {
533 draw_free_temp_verts( stage );
534 FREE( stage );
535 }
536
537
538 static struct pstip_stage *
539 draw_pstip_stage(struct draw_context *draw)
540 {
541 struct pstip_stage *pstip = CALLOC_STRUCT(pstip_stage);
542
543 draw_alloc_temp_verts( &pstip->stage, 8 );
544
545 pstip->stage.draw = draw;
546 pstip->stage.next = NULL;
547 pstip->stage.point = passthrough_point;
548 pstip->stage.line = passthrough_line;
549 pstip->stage.tri = pstip_first_tri;
550 pstip->stage.flush = pstip_flush;
551 pstip->stage.reset_stipple_counter = pstip_reset_stipple_counter;
552 pstip->stage.destroy = pstip_destroy;
553
554 return pstip;
555 }
556
557
558 /*
559 * XXX temporary? solution to mapping a pipe_context to a pstip_stage.
560 */
561
562 #define MAX_CONTEXTS 10
563
564 static struct pipe_context *Pipe[MAX_CONTEXTS];
565 static struct pstip_stage *Stage[MAX_CONTEXTS];
566 static uint NumContexts;
567
568 static void
569 add_pstip_pipe_context(struct pipe_context *pipe, struct pstip_stage *pstip)
570 {
571 assert(NumContexts < MAX_CONTEXTS);
572 Pipe[NumContexts] = pipe;
573 Stage[NumContexts] = pstip;
574 NumContexts++;
575 }
576
577 static struct pstip_stage *
578 pstip_stage_from_pipe(struct pipe_context *pipe)
579 {
580 uint i;
581 for (i = 0; i < NumContexts; i++) {
582 if (Pipe[i] == pipe)
583 return Stage[i];
584 }
585 assert(0);
586 return NULL;
587 }
588
589
590 /**
591 * This function overrides the driver's create_fs_state() function and
592 * will typically be called by the state tracker.
593 */
594 static void *
595 pstip_create_fs_state(struct pipe_context *pipe,
596 const struct pipe_shader_state *fs)
597 {
598 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
599 struct pstip_fragment_shader *aafs = CALLOC_STRUCT(pstip_fragment_shader);
600
601 if (aafs) {
602 aafs->state = *fs;
603
604 /* pass-through */
605 aafs->driver_fs = pstip->driver_create_fs_state(pstip->pipe, fs);
606 }
607
608 return aafs;
609 }
610
611
612 static void
613 pstip_bind_fs_state(struct pipe_context *pipe, void *fs)
614 {
615 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
616 struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs;
617 /* save current */
618 pstip->fs = aafs;
619 /* pass-through */
620 pstip->driver_bind_fs_state(pstip->pipe, aafs->driver_fs);
621 }
622
623
624 static void
625 pstip_delete_fs_state(struct pipe_context *pipe, void *fs)
626 {
627 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
628 struct pstip_fragment_shader *aafs = (struct pstip_fragment_shader *) fs;
629 /* pass-through */
630 pstip->driver_delete_fs_state(pstip->pipe, aafs->driver_fs);
631 FREE(aafs);
632 }
633
634
635 static void
636 pstip_bind_sampler_state(struct pipe_context *pipe,
637 unsigned unit, void *sampler)
638 {
639 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
640 /* save current */
641 pstip->state.sampler[unit] = sampler;
642 /* pass-through */
643 pstip->driver_bind_sampler_state(pstip->pipe, unit, sampler);
644 }
645
646
647 static void
648 pstip_set_sampler_texture(struct pipe_context *pipe,
649 unsigned sampler, struct pipe_texture *texture)
650 {
651 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
652 /* save current */
653 pstip->state.texture[sampler] = texture;
654 /* pass-through */
655 pstip->driver_set_sampler_texture(pstip->pipe, sampler, texture);
656 }
657
658
659 static void
660 pstip_set_polygon_stipple(struct pipe_context *pipe,
661 const struct pipe_poly_stipple *stipple)
662 {
663 struct pstip_stage *pstip = pstip_stage_from_pipe(pipe);
664 /* save current */
665 pstip->state.stipple = stipple;
666 /* pass-through */
667 pstip->driver_set_polygon_stipple(pstip->pipe, stipple);
668
669 pstip_update_texture(pstip);
670 }
671
672
673
674 /**
675 * Called by drivers that want to install this AA line prim stage
676 * into the draw module's pipeline. This will not be used if the
677 * hardware has native support for AA lines.
678 */
679 void
680 draw_install_pstipple_stage(struct draw_context *draw,
681 struct pipe_context *pipe)
682 {
683 struct pstip_stage *pstip;
684
685 /*
686 * Create / install AA line drawing / prim stage
687 */
688 pstip = draw_pstip_stage( draw );
689 assert(pstip);
690 draw->pipeline.pstipple = &pstip->stage;
691
692 pstip->pipe = pipe;
693
694 /* create special texture, sampler state */
695 pstip_create_texture(pstip);
696 pstip_create_sampler(pstip);
697
698 /* save original driver functions */
699 pstip->driver_create_fs_state = pipe->create_fs_state;
700 pstip->driver_bind_fs_state = pipe->bind_fs_state;
701 pstip->driver_delete_fs_state = pipe->delete_fs_state;
702
703 pstip->driver_bind_sampler_state = pipe->bind_sampler_state;
704 pstip->driver_set_sampler_texture = pipe->set_sampler_texture;
705 pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple;
706
707 /* override the driver's functions */
708 pipe->create_fs_state = pstip_create_fs_state;
709 pipe->bind_fs_state = pstip_bind_fs_state;
710 pipe->delete_fs_state = pstip_delete_fs_state;
711
712 pipe->bind_sampler_state = pstip_bind_sampler_state;
713 pipe->set_sampler_texture = pstip_set_sampler_texture;
714 pipe->set_polygon_stipple = pstip_set_polygon_stipple;
715
716 add_pstip_pipe_context(pipe, pstip);
717 }