static void svga_set_polygon_stipple(struct pipe_context *pipe, const struct pipe_poly_stipple *stipple) { struct svga_context *svga = svga_context(pipe); /* release old texture */ pipe_resource_reference(&svga->polygon_stipple.texture, NULL); /* release old sampler view */ if (svga->polygon_stipple.sampler_view) { pipe->sampler_view_destroy(pipe, &svga->polygon_stipple.sampler_view->base); } /* create new stipple texture */ svga->polygon_stipple.texture = util_pstipple_create_stipple_texture(pipe, stipple->stipple); /* create new sampler view */ svga->polygon_stipple.sampler_view = (struct svga_pipe_sampler_view *) util_pstipple_create_sampler_view(pipe, svga->polygon_stipple.texture); /* allocate sampler state, if first time */ if (!svga->polygon_stipple.sampler) { svga->polygon_stipple.sampler = util_pstipple_create_sampler(pipe); } svga->dirty |= SVGA_NEW_STIPPLE; }
/** * Called by drivers that want to install this polygon stipple stage * into the draw module's pipeline. This will not be used if the * hardware has native support for polygon stipple. */ boolean draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe) { struct pstip_stage *pstip; pipe->draw = (void *) draw; /* * Create / install pgon stipple drawing / prim stage */ pstip = draw_pstip_stage( draw, pipe ); if (!pstip) goto fail; draw->pipeline.pstipple = &pstip->stage; /* save original driver functions */ pstip->driver_create_fs_state = pipe->create_fs_state; pstip->driver_bind_fs_state = pipe->bind_fs_state; pstip->driver_delete_fs_state = pipe->delete_fs_state; pstip->driver_bind_sampler_states = pipe->bind_sampler_states; pstip->driver_set_sampler_views = pipe->set_sampler_views; pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; /* create special texture, sampler state */ pstip->texture = util_pstipple_create_stipple_texture(pipe, NULL); if (!pstip->texture) goto fail; pstip->sampler_view = util_pstipple_create_sampler_view(pipe, pstip->texture); if (!pstip->sampler_view) goto fail; pstip->sampler_cso = util_pstipple_create_sampler(pipe); if (!pstip->sampler_cso) goto fail; /* override the driver's functions */ pipe->create_fs_state = pstip_create_fs_state; pipe->bind_fs_state = pstip_bind_fs_state; pipe->delete_fs_state = pstip_delete_fs_state; pipe->bind_sampler_states = pstip_bind_sampler_states; pipe->set_sampler_views = pstip_set_sampler_views; pipe->set_polygon_stipple = pstip_set_polygon_stipple; return TRUE; fail: if (pstip) pstip->stage.destroy( &pstip->stage ); return FALSE; }
/** * This should be called when the polygon stipple pattern changes. * We create a new texture from the stipple pattern and create a new * sampler view. */ static void update_polygon_stipple_pattern(struct softpipe_context *softpipe) { struct pipe_resource *tex; struct pipe_sampler_view *view; tex = util_pstipple_create_stipple_texture(&softpipe->pipe, softpipe->poly_stipple.stipple); pipe_resource_reference(&softpipe->pstipple.texture, tex); pipe_resource_reference(&tex, NULL); view = util_pstipple_create_sampler_view(&softpipe->pipe, softpipe->pstipple.texture); pipe_sampler_view_reference(&softpipe->pstipple.sampler_view, view); pipe_sampler_view_reference(&view, NULL); }