1 /**************************************************************************
3 * Copyright 2008 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 * 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.
37 #include "pipe/p_inlines.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_defines.h"
40 #include "pipe/p_shader_tokens.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
45 #include "tgsi/tgsi_transform.h"
46 #include "tgsi/tgsi_dump.h"
48 #include "draw_context.h"
49 #include "draw_pipe.h"
54 * Subclass of pipe_shader_state to carry extra fragment shader info.
56 struct pstip_fragment_shader
58 struct pipe_shader_state state
;
66 * Subclass of draw_stage
70 struct draw_stage stage
;
73 struct pipe_texture
*texture
;
78 * Currently bound state
80 struct pstip_fragment_shader
*fs
;
82 void *samplers
[PIPE_MAX_SAMPLERS
];
83 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
84 const struct pipe_poly_stipple
*stipple
;
88 * Driver interface/override functions
90 void * (*driver_create_fs_state
)(struct pipe_context
*,
91 const struct pipe_shader_state
*);
92 void (*driver_bind_fs_state
)(struct pipe_context
*, void *);
93 void (*driver_delete_fs_state
)(struct pipe_context
*, void *);
95 void (*driver_bind_sampler_states
)(struct pipe_context
*, unsigned, void **);
97 void (*driver_set_sampler_textures
)(struct pipe_context
*, unsigned,
98 struct pipe_texture
**);
100 void (*driver_set_polygon_stipple
)(struct pipe_context
*,
101 const struct pipe_poly_stipple
*);
103 struct pipe_context
*pipe
;
109 * Subclass of tgsi_transform_context, used for transforming the
110 * user's fragment shader to add the special AA instructions.
112 struct pstip_transform_context
{
113 struct tgsi_transform_context base
;
114 uint tempsUsed
; /**< bitmask */
117 uint samplersUsed
; /**< bitfield of samplers used */
118 int freeSampler
; /** an available sampler for the pstipple */
119 int texTemp
; /**< temp registers */
121 boolean firstInstruction
;
126 * TGSI declaration transform callback.
127 * Look for a free sampler, a free input attrib, and two free temp regs.
130 pstip_transform_decl(struct tgsi_transform_context
*ctx
,
131 struct tgsi_full_declaration
*decl
)
133 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
135 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER
) {
137 for (i
= decl
->DeclarationRange
.First
;
138 i
<= decl
->DeclarationRange
.Last
; i
++) {
139 pctx
->samplersUsed
|= 1 << i
;
142 else if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
143 pctx
->maxInput
= MAX2(pctx
->maxInput
, (int) decl
->DeclarationRange
.Last
);
144 if (decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_POSITION
)
145 pctx
->wincoordInput
= (int) decl
->DeclarationRange
.First
;
147 else if (decl
->Declaration
.File
== TGSI_FILE_TEMPORARY
) {
149 for (i
= decl
->DeclarationRange
.First
;
150 i
<= decl
->DeclarationRange
.Last
; i
++) {
151 pctx
->tempsUsed
|= (1 << i
);
155 ctx
->emit_declaration(ctx
, decl
);
160 pstip_transform_immed(struct tgsi_transform_context
*ctx
,
161 struct tgsi_full_immediate
*immed
)
163 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
169 * Find the lowest zero bit in the given word, or -1 if bitfield is all ones.
172 free_bit(uint bitfield
)
175 for (i
= 0; i
< 32; i
++) {
176 if ((bitfield
& (1 << i
)) == 0)
184 * TGSI instruction transform callback.
185 * Replace writes to result.color w/ a temp reg.
186 * Upon END instruction, insert texture sampling code for antialiasing.
189 pstip_transform_inst(struct tgsi_transform_context
*ctx
,
190 struct tgsi_full_instruction
*inst
)
192 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
194 if (pctx
->firstInstruction
) {
195 /* emit our new declarations before the first instruction */
197 struct tgsi_full_declaration decl
;
198 struct tgsi_full_instruction newInst
;
202 /* find free sampler */
203 pctx
->freeSampler
= free_bit(pctx
->samplersUsed
);
204 if (pctx
->freeSampler
>= PIPE_MAX_SAMPLERS
)
205 pctx
->freeSampler
= PIPE_MAX_SAMPLERS
- 1;
207 if (pctx
->wincoordInput
< 0)
208 wincoordInput
= pctx
->maxInput
+ 1;
210 wincoordInput
= pctx
->wincoordInput
;
212 /* find one free temp reg */
213 for (i
= 0; i
< 32; i
++) {
214 if ((pctx
->tempsUsed
& (1 << i
)) == 0) {
215 /* found a free temp */
216 if (pctx
->texTemp
< 0)
222 assert(pctx
->texTemp
>= 0);
224 if (pctx
->wincoordInput
< 0) {
225 /* declare new position input reg */
226 decl
= tgsi_default_full_declaration();
227 decl
.Declaration
.File
= TGSI_FILE_INPUT
;
228 decl
.Declaration
.Interpolate
= TGSI_INTERPOLATE_LINEAR
; /* XXX? */
229 decl
.Declaration
.Semantic
= 1;
230 decl
.Semantic
.SemanticName
= TGSI_SEMANTIC_POSITION
;
231 decl
.Semantic
.SemanticIndex
= 0;
232 decl
.DeclarationRange
.First
=
233 decl
.DeclarationRange
.Last
= wincoordInput
;
234 ctx
->emit_declaration(ctx
, &decl
);
237 /* declare new sampler */
238 decl
= tgsi_default_full_declaration();
239 decl
.Declaration
.File
= TGSI_FILE_SAMPLER
;
240 decl
.DeclarationRange
.First
=
241 decl
.DeclarationRange
.Last
= pctx
->freeSampler
;
242 ctx
->emit_declaration(ctx
, &decl
);
244 /* declare new temp regs */
245 decl
= tgsi_default_full_declaration();
246 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
247 decl
.DeclarationRange
.First
=
248 decl
.DeclarationRange
.Last
= pctx
->texTemp
;
249 ctx
->emit_declaration(ctx
, &decl
);
251 /* emit immediate = {1/32, 1/32, 1, 1}
252 * The index/position of this immediate will be pctx->numImmed
255 static const float value
[4] = { 1.0/32, 1.0/32, 1.0, 1.0 };
256 struct tgsi_full_immediate immed
;
258 immed
= tgsi_default_full_immediate();
259 immed
.Immediate
.Size
= 1 + size
; /* one for the token itself */
260 immed
.u
.Pointer
= (void *) value
;
261 ctx
->emit_immediate(ctx
, &immed
);
264 pctx
->firstInstruction
= FALSE
;
268 * Insert new MUL/TEX/KILP instructions at start of program
269 * Take gl_FragCoord, divide by 32 (stipple size), sample the
270 * texture and kill fragment if needed.
272 * We'd like to use non-normalized texcoords to index into a RECT
273 * texture, but we can only use GL_REPEAT wrap mode with normalized
277 /* MUL texTemp, INPUT[wincoord], 1/32; */
278 newInst
= tgsi_default_full_instruction();
279 newInst
.Instruction
.Opcode
= TGSI_OPCODE_MUL
;
280 newInst
.Instruction
.NumDstRegs
= 1;
281 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_TEMPORARY
;
282 newInst
.FullDstRegisters
[0].DstRegister
.Index
= pctx
->texTemp
;
283 newInst
.Instruction
.NumSrcRegs
= 2;
284 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_INPUT
;
285 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= wincoordInput
;
286 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_IMMEDIATE
;
287 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= pctx
->numImmed
;
288 ctx
->emit_instruction(ctx
, &newInst
);
290 /* TEX texTemp, texTemp, sampler; */
291 newInst
= tgsi_default_full_instruction();
292 newInst
.Instruction
.Opcode
= TGSI_OPCODE_TEX
;
293 newInst
.Instruction
.NumDstRegs
= 1;
294 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_TEMPORARY
;
295 newInst
.FullDstRegisters
[0].DstRegister
.Index
= pctx
->texTemp
;
296 newInst
.Instruction
.NumSrcRegs
= 2;
297 newInst
.InstructionExtTexture
.Texture
= TGSI_TEXTURE_2D
;
298 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
299 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= pctx
->texTemp
;
300 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
301 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= pctx
->freeSampler
;
302 ctx
->emit_instruction(ctx
, &newInst
);
304 /* KIL -texTemp; # if -texTemp < 0, KILL fragment */
305 newInst
= tgsi_default_full_instruction();
306 newInst
.Instruction
.Opcode
= TGSI_OPCODE_KIL
;
307 newInst
.Instruction
.NumDstRegs
= 0;
308 newInst
.Instruction
.NumSrcRegs
= 1;
309 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
310 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= pctx
->texTemp
;
311 newInst
.FullSrcRegisters
[0].SrcRegister
.Negate
= 1;
312 ctx
->emit_instruction(ctx
, &newInst
);
315 /* emit this instruction */
316 ctx
->emit_instruction(ctx
, inst
);
321 * Generate the frag shader we'll use for doing polygon stipple.
322 * This will be the user's shader prefixed with a TEX and KIL instruction.
325 generate_pstip_fs(struct pstip_stage
*pstip
)
327 const struct pipe_shader_state
*orig_fs
= &pstip
->fs
->state
;
328 /*struct draw_context *draw = pstip->stage.draw;*/
329 struct pipe_shader_state pstip_fs
;
330 struct pstip_transform_context transform
;
334 pstip_fs
= *orig_fs
; /* copy to init */
335 pstip_fs
.tokens
= MALLOC(sizeof(struct tgsi_token
) * MAX
);
336 if (pstip_fs
.tokens
== NULL
)
339 memset(&transform
, 0, sizeof(transform
));
340 transform
.wincoordInput
= -1;
341 transform
.maxInput
= -1;
342 transform
.texTemp
= -1;
343 transform
.firstInstruction
= TRUE
;
344 transform
.base
.transform_instruction
= pstip_transform_inst
;
345 transform
.base
.transform_declaration
= pstip_transform_decl
;
346 transform
.base
.transform_immediate
= pstip_transform_immed
;
348 tgsi_transform_shader(orig_fs
->tokens
,
349 (struct tgsi_token
*) pstip_fs
.tokens
,
350 MAX
, &transform
.base
);
353 tgsi_dump(orig_fs
->tokens
, 0);
354 tgsi_dump(pstip_fs
.tokens
, 0);
357 pstip
->fs
->sampler_unit
= transform
.freeSampler
;
358 assert(pstip
->fs
->sampler_unit
< PIPE_MAX_SAMPLERS
);
360 pstip
->fs
->pstip_fs
= pstip
->driver_create_fs_state(pstip
->pipe
, &pstip_fs
);
367 * Load texture image with current stipple pattern.
370 pstip_update_texture(struct pstip_stage
*pstip
)
372 static const uint bit31
= 1 << 31;
373 struct pipe_context
*pipe
= pstip
->pipe
;
374 struct pipe_screen
*screen
= pipe
->screen
;
375 struct pipe_surface
*surface
;
376 const uint
*stipple
= pstip
->state
.stipple
->stipple
;
380 /* XXX: want to avoid flushing just because we use stipple:
382 pipe
->flush( pipe
, PIPE_FLUSH_TEXTURE_CACHE
, NULL
);
384 surface
= screen
->get_tex_surface(screen
, pstip
->texture
, 0, 0, 0,
385 PIPE_BUFFER_USAGE_CPU_WRITE
);
386 data
= screen
->surface_map(screen
, surface
,
387 PIPE_BUFFER_USAGE_CPU_WRITE
);
390 * Load alpha texture.
391 * Note: 0 means keep the fragment, 255 means kill it.
392 * We'll negate the texel value and use KILP which kills if value
395 for (i
= 0; i
< 32; i
++) {
396 for (j
= 0; j
< 32; j
++) {
397 if (stipple
[i
] & (bit31
>> j
)) {
399 data
[i
* surface
->stride
+ j
] = 0;
403 data
[i
* surface
->stride
+ j
] = 255;
409 screen
->surface_unmap(screen
, surface
);
410 screen
->tex_surface_release(screen
, &surface
);
415 * Create the texture map we'll use for stippling.
418 pstip_create_texture(struct pstip_stage
*pstip
)
420 struct pipe_context
*pipe
= pstip
->pipe
;
421 struct pipe_screen
*screen
= pipe
->screen
;
422 struct pipe_texture texTemp
;
424 memset(&texTemp
, 0, sizeof(texTemp
));
425 texTemp
.target
= PIPE_TEXTURE_2D
;
426 texTemp
.format
= PIPE_FORMAT_A8_UNORM
; /* XXX verify supported by driver! */
427 texTemp
.last_level
= 0;
428 texTemp
.width
[0] = 32;
429 texTemp
.height
[0] = 32;
430 texTemp
.depth
[0] = 1;
431 pf_get_block(texTemp
.format
, &texTemp
.block
);
433 pstip
->texture
= screen
->texture_create(screen
, &texTemp
);
434 if (pstip
->texture
== NULL
)
442 * Create the sampler CSO that'll be used for stippling.
445 pstip_create_sampler(struct pstip_stage
*pstip
)
447 struct pipe_sampler_state sampler
;
448 struct pipe_context
*pipe
= pstip
->pipe
;
450 memset(&sampler
, 0, sizeof(sampler
));
451 sampler
.wrap_s
= PIPE_TEX_WRAP_REPEAT
;
452 sampler
.wrap_t
= PIPE_TEX_WRAP_REPEAT
;
453 sampler
.wrap_r
= PIPE_TEX_WRAP_REPEAT
;
454 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
455 sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
456 sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
457 sampler
.normalized_coords
= 1;
458 sampler
.min_lod
= 0.0f
;
459 sampler
.max_lod
= 0.0f
;
461 pstip
->sampler_cso
= pipe
->create_sampler_state(pipe
, &sampler
);
462 if (pstip
->sampler_cso
== NULL
)
470 * When we're about to draw our first stipple polygon in a batch, this function
471 * is called to tell the driver to bind our modified fragment shader.
474 bind_pstip_fragment_shader(struct pstip_stage
*pstip
)
476 struct draw_context
*draw
= pstip
->stage
.draw
;
477 if (!pstip
->fs
->pstip_fs
&&
478 !generate_pstip_fs(pstip
))
481 draw
->suspend_flushing
= TRUE
;
482 pstip
->driver_bind_fs_state(pstip
->pipe
, pstip
->fs
->pstip_fs
);
483 draw
->suspend_flushing
= FALSE
;
488 static INLINE
struct pstip_stage
*
489 pstip_stage( struct draw_stage
*stage
)
491 return (struct pstip_stage
*) stage
;
496 pstip_first_tri(struct draw_stage
*stage
, struct prim_header
*header
)
498 struct pstip_stage
*pstip
= pstip_stage(stage
);
499 struct pipe_context
*pipe
= pstip
->pipe
;
500 struct draw_context
*draw
= stage
->draw
;
503 assert(stage
->draw
->rasterizer
->poly_stipple_enable
);
505 /* bind our fragprog */
506 if (!bind_pstip_fragment_shader(pstip
)) {
507 stage
->tri
= draw_pipe_passthrough_tri
;
508 stage
->tri(stage
, header
);
513 /* how many samplers? */
514 /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
515 num_samplers
= MAX2(pstip
->num_textures
, pstip
->num_samplers
);
516 num_samplers
= MAX2(num_samplers
, pstip
->fs
->sampler_unit
+ 1);
518 /* plug in our sampler, texture */
519 pstip
->state
.samplers
[pstip
->fs
->sampler_unit
] = pstip
->sampler_cso
;
520 pipe_texture_reference(&pstip
->state
.textures
[pstip
->fs
->sampler_unit
],
523 assert(num_samplers
<= PIPE_MAX_SAMPLERS
);
525 draw
->suspend_flushing
= TRUE
;
526 pstip
->driver_bind_sampler_states(pipe
, num_samplers
, pstip
->state
.samplers
);
527 pstip
->driver_set_sampler_textures(pipe
, num_samplers
, pstip
->state
.textures
);
528 draw
->suspend_flushing
= FALSE
;
530 /* now really draw first triangle */
531 stage
->tri
= draw_pipe_passthrough_tri
;
532 stage
->tri(stage
, header
);
537 pstip_flush(struct draw_stage
*stage
, unsigned flags
)
539 struct draw_context
*draw
= stage
->draw
;
540 struct pstip_stage
*pstip
= pstip_stage(stage
);
541 struct pipe_context
*pipe
= pstip
->pipe
;
543 stage
->tri
= pstip_first_tri
;
544 stage
->next
->flush( stage
->next
, flags
);
546 /* restore original frag shader, texture, sampler state */
547 draw
->suspend_flushing
= TRUE
;
548 pstip
->driver_bind_fs_state(pipe
, pstip
->fs
->driver_fs
);
549 pstip
->driver_bind_sampler_states(pipe
, pstip
->num_samplers
,
550 pstip
->state
.samplers
);
551 pstip
->driver_set_sampler_textures(pipe
, pstip
->num_textures
,
552 pstip
->state
.textures
);
553 draw
->suspend_flushing
= FALSE
;
558 pstip_reset_stipple_counter(struct draw_stage
*stage
)
560 stage
->next
->reset_stipple_counter( stage
->next
);
565 pstip_destroy(struct draw_stage
*stage
)
567 struct pstip_stage
*pstip
= pstip_stage(stage
);
570 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
571 pipe_texture_reference(&pstip
->state
.textures
[i
], NULL
);
574 pstip
->pipe
->delete_sampler_state(pstip
->pipe
, pstip
->sampler_cso
);
576 pipe_texture_release(&pstip
->texture
);
578 draw_free_temp_verts( stage
);
583 static struct pstip_stage
*
584 draw_pstip_stage(struct draw_context
*draw
)
586 struct pstip_stage
*pstip
= CALLOC_STRUCT(pstip_stage
);
588 draw_alloc_temp_verts( &pstip
->stage
, 8 );
590 pstip
->stage
.draw
= draw
;
591 pstip
->stage
.next
= NULL
;
592 pstip
->stage
.point
= draw_pipe_passthrough_point
;
593 pstip
->stage
.line
= draw_pipe_passthrough_line
;
594 pstip
->stage
.tri
= pstip_first_tri
;
595 pstip
->stage
.flush
= pstip_flush
;
596 pstip
->stage
.reset_stipple_counter
= pstip_reset_stipple_counter
;
597 pstip
->stage
.destroy
= pstip_destroy
;
603 static struct pstip_stage
*
604 pstip_stage_from_pipe(struct pipe_context
*pipe
)
606 struct draw_context
*draw
= (struct draw_context
*) pipe
->draw
;
607 return pstip_stage(draw
->pipeline
.pstipple
);
612 * This function overrides the driver's create_fs_state() function and
613 * will typically be called by the state tracker.
616 pstip_create_fs_state(struct pipe_context
*pipe
,
617 const struct pipe_shader_state
*fs
)
619 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
620 struct pstip_fragment_shader
*aafs
= CALLOC_STRUCT(pstip_fragment_shader
);
626 aafs
->driver_fs
= pstip
->driver_create_fs_state(pstip
->pipe
, fs
);
634 pstip_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
636 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
637 struct pstip_fragment_shader
*aafs
= (struct pstip_fragment_shader
*) fs
;
641 pstip
->driver_bind_fs_state(pstip
->pipe
,
642 (aafs
? aafs
->driver_fs
: NULL
));
647 pstip_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
649 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
650 struct pstip_fragment_shader
*aafs
= (struct pstip_fragment_shader
*) fs
;
652 pstip
->driver_delete_fs_state(pstip
->pipe
, aafs
->driver_fs
);
658 pstip_bind_sampler_states(struct pipe_context
*pipe
,
659 unsigned num
, void **sampler
)
661 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
665 memcpy(pstip
->state
.samplers
, sampler
, num
* sizeof(void *));
666 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; i
++) {
667 pstip
->state
.samplers
[i
] = NULL
;
670 pstip
->num_samplers
= num
;
672 pstip
->driver_bind_sampler_states(pstip
->pipe
, num
, sampler
);
677 pstip_set_sampler_textures(struct pipe_context
*pipe
,
678 unsigned num
, struct pipe_texture
**texture
)
680 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
684 for (i
= 0; i
< num
; i
++) {
685 pipe_texture_reference(&pstip
->state
.textures
[i
], texture
[i
]);
687 for (; i
< PIPE_MAX_SAMPLERS
; i
++) {
688 pipe_texture_reference(&pstip
->state
.textures
[i
], NULL
);
691 pstip
->num_textures
= num
;
694 pstip
->driver_set_sampler_textures(pstip
->pipe
, num
, texture
);
699 pstip_set_polygon_stipple(struct pipe_context
*pipe
,
700 const struct pipe_poly_stipple
*stipple
)
702 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
705 pstip
->state
.stipple
= stipple
;
708 pstip
->driver_set_polygon_stipple(pstip
->pipe
, stipple
);
710 pstip_update_texture(pstip
);
715 * Called by drivers that want to install this polygon stipple stage
716 * into the draw module's pipeline. This will not be used if the
717 * hardware has native support for polygon stipple.
720 draw_install_pstipple_stage(struct draw_context
*draw
,
721 struct pipe_context
*pipe
)
723 struct pstip_stage
*pstip
;
725 pipe
->draw
= (void *) draw
;
728 * Create / install pgon stipple drawing / prim stage
730 pstip
= draw_pstip_stage( draw
);
734 draw
->pipeline
.pstipple
= &pstip
->stage
;
738 /* create special texture, sampler state */
739 if (!pstip_create_texture(pstip
))
742 if (!pstip_create_sampler(pstip
))
745 /* save original driver functions */
746 pstip
->driver_create_fs_state
= pipe
->create_fs_state
;
747 pstip
->driver_bind_fs_state
= pipe
->bind_fs_state
;
748 pstip
->driver_delete_fs_state
= pipe
->delete_fs_state
;
750 pstip
->driver_bind_sampler_states
= pipe
->bind_sampler_states
;
751 pstip
->driver_set_sampler_textures
= pipe
->set_sampler_textures
;
752 pstip
->driver_set_polygon_stipple
= pipe
->set_polygon_stipple
;
754 /* override the driver's functions */
755 pipe
->create_fs_state
= pstip_create_fs_state
;
756 pipe
->bind_fs_state
= pstip_bind_fs_state
;
757 pipe
->delete_fs_state
= pstip_delete_fs_state
;
759 pipe
->bind_sampler_states
= pstip_bind_sampler_states
;
760 pipe
->set_sampler_textures
= pstip_set_sampler_textures
;
761 pipe
->set_polygon_stipple
= pstip_set_polygon_stipple
;
767 pstip
->stage
.destroy( &pstip
->stage
);