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_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"
43 #include "tgsi/util/tgsi_transform.h"
44 #include "tgsi/util/tgsi_dump.h"
46 #include "draw_context.h"
47 #include "draw_pipe.h"
52 * Subclass of pipe_shader_state to carry extra fragment shader info.
54 struct pstip_fragment_shader
56 struct pipe_shader_state state
;
64 * Subclass of draw_stage
68 struct draw_stage stage
;
71 struct pipe_texture
*texture
;
76 * Currently bound state
78 struct pstip_fragment_shader
*fs
;
80 void *samplers
[PIPE_MAX_SAMPLERS
];
81 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
82 const struct pipe_poly_stipple
*stipple
;
86 * Driver interface/override functions
88 void * (*driver_create_fs_state
)(struct pipe_context
*,
89 const struct pipe_shader_state
*);
90 void (*driver_bind_fs_state
)(struct pipe_context
*, void *);
91 void (*driver_delete_fs_state
)(struct pipe_context
*, void *);
93 void (*driver_bind_sampler_states
)(struct pipe_context
*, unsigned, void **);
95 void (*driver_set_sampler_textures
)(struct pipe_context
*, unsigned,
96 struct pipe_texture
**);
98 void (*driver_set_polygon_stipple
)(struct pipe_context
*,
99 const struct pipe_poly_stipple
*);
101 struct pipe_context
*pipe
;
107 * Subclass of tgsi_transform_context, used for transforming the
108 * user's fragment shader to add the special AA instructions.
110 struct pstip_transform_context
{
111 struct tgsi_transform_context base
;
112 uint tempsUsed
; /**< bitmask */
115 uint samplersUsed
; /**< bitfield of samplers used */
116 int freeSampler
; /** an available sampler for the pstipple */
117 int texTemp
; /**< temp registers */
119 boolean firstInstruction
;
124 * TGSI declaration transform callback.
125 * Look for a free sampler, a free input attrib, and two free temp regs.
128 pstip_transform_decl(struct tgsi_transform_context
*ctx
,
129 struct tgsi_full_declaration
*decl
)
131 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
133 if (decl
->Declaration
.File
== TGSI_FILE_SAMPLER
) {
135 for (i
= decl
->DeclarationRange
.First
;
136 i
<= decl
->DeclarationRange
.Last
; i
++) {
137 pctx
->samplersUsed
|= 1 << i
;
140 else if (decl
->Declaration
.File
== TGSI_FILE_INPUT
) {
141 pctx
->maxInput
= MAX2(pctx
->maxInput
, (int) decl
->DeclarationRange
.Last
);
142 if (decl
->Semantic
.SemanticName
== TGSI_SEMANTIC_POSITION
)
143 pctx
->wincoordInput
= (int) decl
->DeclarationRange
.First
;
145 else if (decl
->Declaration
.File
== TGSI_FILE_TEMPORARY
) {
147 for (i
= decl
->DeclarationRange
.First
;
148 i
<= decl
->DeclarationRange
.Last
; i
++) {
149 pctx
->tempsUsed
|= (1 << i
);
153 ctx
->emit_declaration(ctx
, decl
);
158 pstip_transform_immed(struct tgsi_transform_context
*ctx
,
159 struct tgsi_full_immediate
*immed
)
161 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
167 * Find the lowest zero bit in the given word, or -1 if bitfield is all ones.
170 free_bit(uint bitfield
)
173 for (i
= 0; i
< 32; i
++) {
174 if ((bitfield
& (1 << i
)) == 0)
182 * TGSI instruction transform callback.
183 * Replace writes to result.color w/ a temp reg.
184 * Upon END instruction, insert texture sampling code for antialiasing.
187 pstip_transform_inst(struct tgsi_transform_context
*ctx
,
188 struct tgsi_full_instruction
*inst
)
190 struct pstip_transform_context
*pctx
= (struct pstip_transform_context
*) ctx
;
192 if (pctx
->firstInstruction
) {
193 /* emit our new declarations before the first instruction */
195 struct tgsi_full_declaration decl
;
196 struct tgsi_full_instruction newInst
;
200 /* find free sampler */
201 pctx
->freeSampler
= free_bit(pctx
->samplersUsed
);
202 if (pctx
->freeSampler
>= PIPE_MAX_SAMPLERS
)
203 pctx
->freeSampler
= PIPE_MAX_SAMPLERS
- 1;
205 if (pctx
->wincoordInput
< 0)
206 wincoordInput
= pctx
->maxInput
+ 1;
208 wincoordInput
= pctx
->wincoordInput
;
210 /* find one free temp reg */
211 for (i
= 0; i
< 32; i
++) {
212 if ((pctx
->tempsUsed
& (1 << i
)) == 0) {
213 /* found a free temp */
214 if (pctx
->texTemp
< 0)
220 assert(pctx
->texTemp
>= 0);
222 if (pctx
->wincoordInput
< 0) {
223 /* declare new position input reg */
224 decl
= tgsi_default_full_declaration();
225 decl
.Declaration
.File
= TGSI_FILE_INPUT
;
226 decl
.Declaration
.Interpolate
= TGSI_INTERPOLATE_LINEAR
; /* XXX? */
227 decl
.Declaration
.Semantic
= 1;
228 decl
.Semantic
.SemanticName
= TGSI_SEMANTIC_POSITION
;
229 decl
.Semantic
.SemanticIndex
= 0;
230 decl
.DeclarationRange
.First
=
231 decl
.DeclarationRange
.Last
= wincoordInput
;
232 ctx
->emit_declaration(ctx
, &decl
);
235 /* declare new sampler */
236 decl
= tgsi_default_full_declaration();
237 decl
.Declaration
.File
= TGSI_FILE_SAMPLER
;
238 decl
.DeclarationRange
.First
=
239 decl
.DeclarationRange
.Last
= pctx
->freeSampler
;
240 ctx
->emit_declaration(ctx
, &decl
);
242 /* declare new temp regs */
243 decl
= tgsi_default_full_declaration();
244 decl
.Declaration
.File
= TGSI_FILE_TEMPORARY
;
245 decl
.DeclarationRange
.First
=
246 decl
.DeclarationRange
.Last
= pctx
->texTemp
;
247 ctx
->emit_declaration(ctx
, &decl
);
249 /* emit immediate = {1/32, 1/32, 1, 1}
250 * The index/position of this immediate will be pctx->numImmed
253 static const float value
[4] = { 1.0/32, 1.0/32, 1.0, 1.0 };
254 struct tgsi_full_immediate immed
;
256 immed
= tgsi_default_full_immediate();
257 immed
.Immediate
.Size
= 1 + size
; /* one for the token itself */
258 immed
.u
.Pointer
= (void *) value
;
259 ctx
->emit_immediate(ctx
, &immed
);
262 pctx
->firstInstruction
= FALSE
;
266 * Insert new MUL/TEX/KILP instructions at start of program
267 * Take gl_FragCoord, divide by 32 (stipple size), sample the
268 * texture and kill fragment if needed.
270 * We'd like to use non-normalized texcoords to index into a RECT
271 * texture, but we can only use GL_REPEAT wrap mode with normalized
275 /* MUL texTemp, INPUT[wincoord], 1/32; */
276 newInst
= tgsi_default_full_instruction();
277 newInst
.Instruction
.Opcode
= TGSI_OPCODE_MUL
;
278 newInst
.Instruction
.NumDstRegs
= 1;
279 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_TEMPORARY
;
280 newInst
.FullDstRegisters
[0].DstRegister
.Index
= pctx
->texTemp
;
281 newInst
.Instruction
.NumSrcRegs
= 2;
282 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_INPUT
;
283 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= wincoordInput
;
284 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_IMMEDIATE
;
285 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= pctx
->numImmed
;
286 ctx
->emit_instruction(ctx
, &newInst
);
288 /* TEX texTemp, texTemp, sampler; */
289 newInst
= tgsi_default_full_instruction();
290 newInst
.Instruction
.Opcode
= TGSI_OPCODE_TEX
;
291 newInst
.Instruction
.NumDstRegs
= 1;
292 newInst
.FullDstRegisters
[0].DstRegister
.File
= TGSI_FILE_TEMPORARY
;
293 newInst
.FullDstRegisters
[0].DstRegister
.Index
= pctx
->texTemp
;
294 newInst
.Instruction
.NumSrcRegs
= 2;
295 newInst
.InstructionExtTexture
.Texture
= TGSI_TEXTURE_2D
;
296 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
297 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= pctx
->texTemp
;
298 newInst
.FullSrcRegisters
[1].SrcRegister
.File
= TGSI_FILE_SAMPLER
;
299 newInst
.FullSrcRegisters
[1].SrcRegister
.Index
= pctx
->freeSampler
;
300 ctx
->emit_instruction(ctx
, &newInst
);
302 /* KILP texTemp; # if texTemp < 0, KILL fragment */
303 newInst
= tgsi_default_full_instruction();
304 newInst
.Instruction
.Opcode
= TGSI_OPCODE_KILP
;
305 newInst
.Instruction
.NumDstRegs
= 0;
306 newInst
.Instruction
.NumSrcRegs
= 1;
307 newInst
.FullSrcRegisters
[0].SrcRegister
.File
= TGSI_FILE_TEMPORARY
;
308 newInst
.FullSrcRegisters
[0].SrcRegister
.Index
= pctx
->texTemp
;
309 newInst
.FullSrcRegisters
[0].SrcRegister
.Negate
= 1;
310 ctx
->emit_instruction(ctx
, &newInst
);
313 /* emit this instruction */
314 ctx
->emit_instruction(ctx
, inst
);
319 * Generate the frag shader we'll use for doing polygon stipple.
320 * This will be the user's shader prefixed with a TEX and KIL instruction.
323 generate_pstip_fs(struct pstip_stage
*pstip
)
325 const struct pipe_shader_state
*orig_fs
= &pstip
->fs
->state
;
326 /*struct draw_context *draw = pstip->stage.draw;*/
327 struct pipe_shader_state pstip_fs
;
328 struct pstip_transform_context transform
;
332 pstip_fs
= *orig_fs
; /* copy to init */
333 pstip_fs
.tokens
= MALLOC(sizeof(struct tgsi_token
) * MAX
);
334 if (pstip_fs
.tokens
== NULL
)
337 memset(&transform
, 0, sizeof(transform
));
338 transform
.wincoordInput
= -1;
339 transform
.maxInput
= -1;
340 transform
.texTemp
= -1;
341 transform
.firstInstruction
= TRUE
;
342 transform
.base
.transform_instruction
= pstip_transform_inst
;
343 transform
.base
.transform_declaration
= pstip_transform_decl
;
344 transform
.base
.transform_immediate
= pstip_transform_immed
;
346 tgsi_transform_shader(orig_fs
->tokens
,
347 (struct tgsi_token
*) pstip_fs
.tokens
,
348 MAX
, &transform
.base
);
351 tgsi_dump(orig_fs
->tokens
, 0);
352 tgsi_dump(pstip_fs
.tokens
, 0);
355 pstip
->fs
->sampler_unit
= transform
.freeSampler
;
356 assert(pstip
->fs
->sampler_unit
< PIPE_MAX_SAMPLERS
);
358 pstip
->fs
->pstip_fs
= pstip
->driver_create_fs_state(pstip
->pipe
, &pstip_fs
);
365 * Load texture image with current stipple pattern.
368 pstip_update_texture(struct pstip_stage
*pstip
)
370 static const uint bit31
= 1 << 31;
371 struct pipe_context
*pipe
= pstip
->pipe
;
372 struct pipe_screen
*screen
= pipe
->screen
;
373 struct pipe_surface
*surface
;
374 const uint
*stipple
= pstip
->state
.stipple
->stipple
;
378 /* XXX: want to avoid flushing just because we use stipple:
380 pipe
->flush( pipe
, PIPE_FLUSH_TEXTURE_CACHE
, NULL
);
382 surface
= screen
->get_tex_surface(screen
, pstip
->texture
, 0, 0, 0,
383 PIPE_BUFFER_USAGE_CPU_WRITE
);
384 data
= screen
->surface_map(screen
, surface
,
385 PIPE_BUFFER_USAGE_CPU_WRITE
);
388 * Load alpha texture.
389 * Note: 0 means keep the fragment, 255 means kill it.
390 * We'll negate the texel value and use KILP which kills if value
393 for (i
= 0; i
< 32; i
++) {
394 for (j
= 0; j
< 32; j
++) {
395 if (stipple
[i
] & (bit31
>> j
)) {
397 data
[i
* surface
->stride
+ j
] = 0;
401 data
[i
* surface
->stride
+ j
] = 255;
407 screen
->surface_unmap(screen
, surface
);
408 screen
->tex_surface_release(screen
, &surface
);
413 * Create the texture map we'll use for stippling.
416 pstip_create_texture(struct pstip_stage
*pstip
)
418 struct pipe_context
*pipe
= pstip
->pipe
;
419 struct pipe_screen
*screen
= pipe
->screen
;
420 struct pipe_texture texTemp
;
422 memset(&texTemp
, 0, sizeof(texTemp
));
423 texTemp
.target
= PIPE_TEXTURE_2D
;
424 texTemp
.format
= PIPE_FORMAT_A8_UNORM
; /* XXX verify supported by driver! */
425 texTemp
.last_level
= 0;
426 texTemp
.width
[0] = 32;
427 texTemp
.height
[0] = 32;
428 texTemp
.depth
[0] = 1;
429 pf_get_block(texTemp
.format
, &texTemp
.block
);
431 pstip
->texture
= screen
->texture_create(screen
, &texTemp
);
432 if (pstip
->texture
== NULL
)
440 * Create the sampler CSO that'll be used for stippling.
443 pstip_create_sampler(struct pstip_stage
*pstip
)
445 struct pipe_sampler_state sampler
;
446 struct pipe_context
*pipe
= pstip
->pipe
;
448 memset(&sampler
, 0, sizeof(sampler
));
449 sampler
.wrap_s
= PIPE_TEX_WRAP_REPEAT
;
450 sampler
.wrap_t
= PIPE_TEX_WRAP_REPEAT
;
451 sampler
.wrap_r
= PIPE_TEX_WRAP_REPEAT
;
452 sampler
.min_mip_filter
= PIPE_TEX_MIPFILTER_NONE
;
453 sampler
.min_img_filter
= PIPE_TEX_FILTER_NEAREST
;
454 sampler
.mag_img_filter
= PIPE_TEX_FILTER_NEAREST
;
455 sampler
.normalized_coords
= 1;
456 sampler
.min_lod
= 0.0f
;
457 sampler
.max_lod
= 0.0f
;
459 pstip
->sampler_cso
= pipe
->create_sampler_state(pipe
, &sampler
);
460 if (pstip
->sampler_cso
== NULL
)
468 * When we're about to draw our first stipple polygon in a batch, this function
469 * is called to tell the driver to bind our modified fragment shader.
472 bind_pstip_fragment_shader(struct pstip_stage
*pstip
)
474 struct draw_context
*draw
= pstip
->stage
.draw
;
475 if (!pstip
->fs
->pstip_fs
&&
476 !generate_pstip_fs(pstip
))
479 draw
->suspend_flushing
= TRUE
;
480 pstip
->driver_bind_fs_state(pstip
->pipe
, pstip
->fs
->pstip_fs
);
481 draw
->suspend_flushing
= FALSE
;
486 static INLINE
struct pstip_stage
*
487 pstip_stage( struct draw_stage
*stage
)
489 return (struct pstip_stage
*) stage
;
494 pstip_first_tri(struct draw_stage
*stage
, struct prim_header
*header
)
496 struct pstip_stage
*pstip
= pstip_stage(stage
);
497 struct pipe_context
*pipe
= pstip
->pipe
;
498 struct draw_context
*draw
= stage
->draw
;
501 assert(stage
->draw
->rasterizer
->poly_stipple_enable
);
503 /* bind our fragprog */
504 if (!bind_pstip_fragment_shader(pstip
)) {
505 stage
->tri
= draw_pipe_passthrough_tri
;
506 stage
->tri(stage
, header
);
511 /* how many samplers? */
512 /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
513 num_samplers
= MAX2(pstip
->num_textures
, pstip
->num_samplers
);
514 num_samplers
= MAX2(num_samplers
, pstip
->fs
->sampler_unit
+ 1);
516 /* plug in our sampler, texture */
517 pstip
->state
.samplers
[pstip
->fs
->sampler_unit
] = pstip
->sampler_cso
;
518 pipe_texture_reference(&pstip
->state
.textures
[pstip
->fs
->sampler_unit
],
521 assert(num_samplers
<= PIPE_MAX_SAMPLERS
);
523 draw
->suspend_flushing
= TRUE
;
524 pstip
->driver_bind_sampler_states(pipe
, num_samplers
, pstip
->state
.samplers
);
525 pstip
->driver_set_sampler_textures(pipe
, num_samplers
, pstip
->state
.textures
);
526 draw
->suspend_flushing
= FALSE
;
528 /* now really draw first triangle */
529 stage
->tri
= draw_pipe_passthrough_tri
;
530 stage
->tri(stage
, header
);
535 pstip_flush(struct draw_stage
*stage
, unsigned flags
)
537 struct draw_context
*draw
= stage
->draw
;
538 struct pstip_stage
*pstip
= pstip_stage(stage
);
539 struct pipe_context
*pipe
= pstip
->pipe
;
541 stage
->tri
= pstip_first_tri
;
542 stage
->next
->flush( stage
->next
, flags
);
544 /* restore original frag shader, texture, sampler state */
545 draw
->suspend_flushing
= TRUE
;
546 pstip
->driver_bind_fs_state(pipe
, pstip
->fs
->driver_fs
);
547 pstip
->driver_bind_sampler_states(pipe
, pstip
->num_samplers
,
548 pstip
->state
.samplers
);
549 pstip
->driver_set_sampler_textures(pipe
, pstip
->num_textures
,
550 pstip
->state
.textures
);
551 draw
->suspend_flushing
= FALSE
;
556 pstip_reset_stipple_counter(struct draw_stage
*stage
)
558 stage
->next
->reset_stipple_counter( stage
->next
);
563 pstip_destroy(struct draw_stage
*stage
)
565 struct pstip_stage
*pstip
= pstip_stage(stage
);
568 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
569 pipe_texture_reference(&pstip
->state
.textures
[i
], NULL
);
572 pstip
->pipe
->delete_sampler_state(pstip
->pipe
, pstip
->sampler_cso
);
574 pipe_texture_release(&pstip
->texture
);
576 draw_free_temp_verts( stage
);
581 static struct pstip_stage
*
582 draw_pstip_stage(struct draw_context
*draw
)
584 struct pstip_stage
*pstip
= CALLOC_STRUCT(pstip_stage
);
586 draw_alloc_temp_verts( &pstip
->stage
, 8 );
588 pstip
->stage
.draw
= draw
;
589 pstip
->stage
.next
= NULL
;
590 pstip
->stage
.point
= draw_pipe_passthrough_point
;
591 pstip
->stage
.line
= draw_pipe_passthrough_line
;
592 pstip
->stage
.tri
= pstip_first_tri
;
593 pstip
->stage
.flush
= pstip_flush
;
594 pstip
->stage
.reset_stipple_counter
= pstip_reset_stipple_counter
;
595 pstip
->stage
.destroy
= pstip_destroy
;
601 static struct pstip_stage
*
602 pstip_stage_from_pipe(struct pipe_context
*pipe
)
604 struct draw_context
*draw
= (struct draw_context
*) pipe
->draw
;
605 return pstip_stage(draw
->pipeline
.pstipple
);
610 * This function overrides the driver's create_fs_state() function and
611 * will typically be called by the state tracker.
614 pstip_create_fs_state(struct pipe_context
*pipe
,
615 const struct pipe_shader_state
*fs
)
617 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
618 struct pstip_fragment_shader
*aafs
= CALLOC_STRUCT(pstip_fragment_shader
);
624 aafs
->driver_fs
= pstip
->driver_create_fs_state(pstip
->pipe
, fs
);
632 pstip_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
634 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
635 struct pstip_fragment_shader
*aafs
= (struct pstip_fragment_shader
*) fs
;
639 pstip
->driver_bind_fs_state(pstip
->pipe
,
640 (aafs
? aafs
->driver_fs
: NULL
));
645 pstip_delete_fs_state(struct pipe_context
*pipe
, void *fs
)
647 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
648 struct pstip_fragment_shader
*aafs
= (struct pstip_fragment_shader
*) fs
;
650 pstip
->driver_delete_fs_state(pstip
->pipe
, aafs
->driver_fs
);
656 pstip_bind_sampler_states(struct pipe_context
*pipe
,
657 unsigned num
, void **sampler
)
659 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
663 memcpy(pstip
->state
.samplers
, sampler
, num
* sizeof(void *));
664 for (i
= num
; i
< PIPE_MAX_SAMPLERS
; i
++) {
665 pstip
->state
.samplers
[i
] = NULL
;
668 pstip
->num_samplers
= num
;
670 pstip
->driver_bind_sampler_states(pstip
->pipe
, num
, sampler
);
675 pstip_set_sampler_textures(struct pipe_context
*pipe
,
676 unsigned num
, struct pipe_texture
**texture
)
678 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
682 for (i
= 0; i
< num
; i
++) {
683 pipe_texture_reference(&pstip
->state
.textures
[i
], texture
[i
]);
685 for (; i
< PIPE_MAX_SAMPLERS
; i
++) {
686 pipe_texture_reference(&pstip
->state
.textures
[i
], NULL
);
689 pstip
->num_textures
= num
;
692 pstip
->driver_set_sampler_textures(pstip
->pipe
, num
, texture
);
697 pstip_set_polygon_stipple(struct pipe_context
*pipe
,
698 const struct pipe_poly_stipple
*stipple
)
700 struct pstip_stage
*pstip
= pstip_stage_from_pipe(pipe
);
703 pstip
->state
.stipple
= stipple
;
706 pstip
->driver_set_polygon_stipple(pstip
->pipe
, stipple
);
708 pstip_update_texture(pstip
);
713 * Called by drivers that want to install this polygon stipple stage
714 * into the draw module's pipeline. This will not be used if the
715 * hardware has native support for polygon stipple.
718 draw_install_pstipple_stage(struct draw_context
*draw
,
719 struct pipe_context
*pipe
)
721 struct pstip_stage
*pstip
;
723 pipe
->draw
= (void *) draw
;
726 * Create / install pgon stipple drawing / prim stage
728 pstip
= draw_pstip_stage( draw
);
732 draw
->pipeline
.pstipple
= &pstip
->stage
;
736 /* create special texture, sampler state */
737 if (!pstip_create_texture(pstip
))
740 if (!pstip_create_sampler(pstip
))
743 /* save original driver functions */
744 pstip
->driver_create_fs_state
= pipe
->create_fs_state
;
745 pstip
->driver_bind_fs_state
= pipe
->bind_fs_state
;
746 pstip
->driver_delete_fs_state
= pipe
->delete_fs_state
;
748 pstip
->driver_bind_sampler_states
= pipe
->bind_sampler_states
;
749 pstip
->driver_set_sampler_textures
= pipe
->set_sampler_textures
;
750 pstip
->driver_set_polygon_stipple
= pipe
->set_polygon_stipple
;
752 /* override the driver's functions */
753 pipe
->create_fs_state
= pstip_create_fs_state
;
754 pipe
->bind_fs_state
= pstip_bind_fs_state
;
755 pipe
->delete_fs_state
= pstip_delete_fs_state
;
757 pipe
->bind_sampler_states
= pstip_bind_sampler_states
;
758 pipe
->set_sampler_textures
= pstip_set_sampler_textures
;
759 pipe
->set_polygon_stipple
= pstip_set_polygon_stipple
;
765 pstip
->stage
.destroy( &pstip
->stage
);