static void aaline_flush(struct draw_stage *stage, unsigned flags) { struct draw_context *draw = stage->draw; struct aaline_stage *aaline = aaline_stage(stage); struct pipe_context *pipe = draw->pipe; stage->line = aaline_first_line; stage->next->flush( stage->next, flags ); /* restore original frag shader, texture, sampler state */ draw->suspend_flushing = TRUE; aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs); aaline->driver_bind_sampler_states(pipe, aaline->num_samplers, aaline->state.sampler); aaline->driver_set_sampler_views(pipe, aaline->num_sampler_views, aaline->state.sampler_views); /* restore original rasterizer state */ if (draw->rast_handle) { pipe->bind_rasterizer_state(pipe, draw->rast_handle); } draw->suspend_flushing = FALSE; draw_remove_extra_vertex_attribs(draw); }
static void aaline_destroy(struct draw_stage *stage) { struct aaline_stage *aaline = aaline_stage(stage); struct pipe_context *pipe = stage->draw->pipe; uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); } if (aaline->sampler_cso) pipe->delete_sampler_state(pipe, aaline->sampler_cso); if (aaline->texture) pipe_resource_reference(&aaline->texture, NULL); if (aaline->sampler_view) { pipe_sampler_view_reference(&aaline->sampler_view, NULL); } draw_free_temp_verts( stage ); FREE( stage ); }
static void aaline_destroy(struct draw_stage *stage) { struct aaline_stage *aaline = aaline_stage(stage); struct pipe_context *pipe = stage->draw->pipe; uint i; for (i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) { pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); } if (aaline->sampler_cso) pipe->delete_sampler_state(pipe, aaline->sampler_cso); if (aaline->texture) pipe_resource_reference(&aaline->texture, NULL); if (aaline->sampler_view) { pipe_sampler_view_reference(&aaline->sampler_view, NULL); } draw_free_temp_verts( stage ); /* restore the old entry points */ pipe->create_fs_state = aaline->driver_create_fs_state; pipe->bind_fs_state = aaline->driver_bind_fs_state; pipe->delete_fs_state = aaline->driver_delete_fs_state; pipe->bind_sampler_states = aaline->driver_bind_sampler_states; pipe->set_sampler_views = aaline->driver_set_sampler_views; FREE( stage ); }
static void aaline_first_line(struct draw_stage *stage, struct prim_header *header) { auto struct aaline_stage *aaline = aaline_stage(stage); struct draw_context *draw = stage->draw; struct pipe_context *pipe = draw->pipe; const struct pipe_rasterizer_state *rast = draw->rasterizer; uint num_samplers; void *r; assert(draw->rasterizer->line_smooth); if (draw->rasterizer->line_width <= 2.2) aaline->half_line_width = 1.1f; else aaline->half_line_width = 0.5f * draw->rasterizer->line_width; /* * Bind (generate) our fragprog, sampler and texture */ if (!bind_aaline_fragment_shader(aaline)) { stage->line = draw_pipe_passthrough_line; stage->line(stage, header); return; } /* update vertex attrib info */ aaline->tex_slot = draw_current_shader_outputs(draw); aaline->pos_slot = draw_current_shader_position_output(draw);; /* allocate the extra post-transformed vertex attribute */ (void) draw_alloc_extra_vertex_attrib(draw, TGSI_SEMANTIC_GENERIC, aaline->fs->generic_attrib); /* how many samplers? */ /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers); num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1); aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso; pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit], aaline->sampler_view); draw->suspend_flushing = TRUE; aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler); aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views); /* Disable triangle culling, stippling, unfilled mode etc. */ r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); pipe->bind_rasterizer_state(pipe, r); draw->suspend_flushing = FALSE; /* now really draw first line */ stage->line = aaline_line; stage->line(stage, header); }
static void aaline_first_line(struct draw_stage *stage, struct prim_header *header) { auto struct aaline_stage *aaline = aaline_stage(stage); struct draw_context *draw = stage->draw; struct pipe_context *pipe = draw->pipe; const struct pipe_rasterizer_state *rast = draw->rasterizer; uint num_samplers; void *r; assert(draw->rasterizer->line_smooth); if (draw->rasterizer->line_width <= 2.2) aaline->half_line_width = 1.1f; else aaline->half_line_width = 0.5f * draw->rasterizer->line_width; /* * Bind (generate) our fragprog, sampler and texture */ if (!bind_aaline_fragment_shader(aaline)) { stage->line = draw_pipe_passthrough_line; stage->line(stage, header); return; } draw_aaline_prepare_outputs(draw, draw->pipeline.aaline); /* how many samplers? */ /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers); num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1); aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso; pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit], aaline->sampler_view); draw->suspend_flushing = TRUE; aaline->driver_bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT, 0, num_samplers, aaline->state.sampler); aaline->driver_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_samplers, aaline->state.sampler_views); /* Disable triangle culling, stippling, unfilled mode etc. */ r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade); pipe->bind_rasterizer_state(pipe, r); draw->suspend_flushing = FALSE; /* now really draw first line */ stage->line = aaline_line; stage->line(stage, header); }
static struct aaline_stage * aaline_stage_from_pipe(struct pipe_context *pipe) { struct draw_context *draw = (struct draw_context *) pipe->draw; if (draw) { return aaline_stage(draw->pipeline.aaline); } else { return NULL; } }
static void aaline_first_line(struct draw_stage *stage, struct prim_header *header) { auto struct aaline_stage *aaline = aaline_stage(stage); struct draw_context *draw = stage->draw; struct pipe_context *pipe = aaline->pipe; uint num_samplers; assert(draw->rasterizer->line_smooth); if (draw->rasterizer->line_width <= 3.0) aaline->half_line_width = 1.5f; else aaline->half_line_width = 0.5f * draw->rasterizer->line_width; /* * Bind (generate) our fragprog, sampler and texture */ if (!bind_aaline_fragment_shader(aaline)) { stage->line = draw_pipe_passthrough_line; stage->line(stage, header); return; } /* update vertex attrib info */ aaline->tex_slot = draw->vs.num_vs_outputs; aaline->pos_slot = draw->vs.position_output; /* advertise the extra post-transformed vertex attribute */ draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC; draw->extra_vp_outputs.semantic_index = aaline->fs->generic_attrib; draw->extra_vp_outputs.slot = aaline->tex_slot; /* how many samplers? */ /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ num_samplers = MAX2(aaline->num_textures, aaline->num_samplers); num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1); aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso; pipe_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit], aaline->texture); draw->suspend_flushing = TRUE; aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler); aaline->driver_set_sampler_textures(pipe, num_samplers, aaline->state.texture); draw->suspend_flushing = FALSE; /* now really draw first line */ stage->line = aaline_line; stage->line(stage, header); }
void draw_aaline_prepare_outputs(struct draw_context *draw, struct draw_stage *stage) { struct aaline_stage *aaline = aaline_stage(stage); const struct pipe_rasterizer_state *rast = draw->rasterizer; /* update vertex attrib info */ aaline->pos_slot = draw_current_shader_position_output(draw);; if (!rast->line_smooth) return; /* allocate the extra post-transformed vertex attribute */ aaline->tex_slot = draw_alloc_extra_vertex_attrib(draw, TGSI_SEMANTIC_GENERIC, aaline->fs->generic_attrib); }
static void aaline_destroy(struct draw_stage *stage) { struct aaline_stage *aaline = aaline_stage(stage); uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&aaline->state.texture[i], NULL); } if (aaline->sampler_cso) aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso); if (aaline->texture) pipe_texture_release(&aaline->texture); draw_free_temp_verts( stage ); FREE( stage ); }
static void aaline_flush(struct draw_stage *stage, unsigned flags) { struct draw_context *draw = stage->draw; struct aaline_stage *aaline = aaline_stage(stage); struct pipe_context *pipe = aaline->pipe; stage->line = aaline_first_line; stage->next->flush( stage->next, flags ); /* restore original frag shader, texture, sampler state */ draw->suspend_flushing = TRUE; aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs); aaline->driver_bind_sampler_states(pipe, aaline->num_samplers, aaline->state.sampler); aaline->driver_set_sampler_textures(pipe, aaline->num_textures, aaline->state.texture); draw->suspend_flushing = FALSE; draw->extra_vp_outputs.slot = 0; }
/** * Draw a wide line by drawing a quad, using geometry which will * fullfill GL's antialiased line requirements. */ static void aaline_line(struct draw_stage *stage, struct prim_header *header) { const struct aaline_stage *aaline = aaline_stage(stage); const float half_width = aaline->half_line_width; struct prim_header tri; struct vertex_header *v[8]; uint texPos = aaline->tex_slot; uint posPos = aaline->pos_slot; float *pos, *tex; float dx = header->v[1]->data[posPos][0] - header->v[0]->data[posPos][0]; float dy = header->v[1]->data[posPos][1] - header->v[0]->data[posPos][1]; double a = atan2(dy, dx); float c_a = (float) cos(a), s_a = (float) sin(a); uint i; /* XXX the ends of lines aren't quite perfect yet, but probably passable */ dx = 0.5F * half_width; dy = half_width; /* allocate/dup new verts */ for (i = 0; i < 8; i++) { v[i] = dup_vert(stage, header->v[i/4], i); } /* * Quad strip for line from v0 to v1 (*=endpoints): * * 1 3 5 7 * +---+---------------------+---+ * | | * | *v0 v1* | * | | * +---+---------------------+---+ * 0 2 4 6 */ /* new verts */ pos = v[0]->data[posPos]; pos[0] += (-dx * c_a - dy * s_a); pos[1] += (-dx * s_a + dy * c_a); pos = v[1]->data[posPos]; pos[0] += (-dx * c_a - -dy * s_a); pos[1] += (-dx * s_a + -dy * c_a); pos = v[2]->data[posPos]; pos[0] += ( dx * c_a - dy * s_a); pos[1] += ( dx * s_a + dy * c_a); pos = v[3]->data[posPos]; pos[0] += ( dx * c_a - -dy * s_a); pos[1] += ( dx * s_a + -dy * c_a); pos = v[4]->data[posPos]; pos[0] += (-dx * c_a - dy * s_a); pos[1] += (-dx * s_a + dy * c_a); pos = v[5]->data[posPos]; pos[0] += (-dx * c_a - -dy * s_a); pos[1] += (-dx * s_a + -dy * c_a); pos = v[6]->data[posPos]; pos[0] += ( dx * c_a - dy * s_a); pos[1] += ( dx * s_a + dy * c_a); pos = v[7]->data[posPos]; pos[0] += ( dx * c_a - -dy * s_a); pos[1] += ( dx * s_a + -dy * c_a); /* new texcoords */ tex = v[0]->data[texPos]; ASSIGN_4V(tex, 0, 0, 0, 1); tex = v[1]->data[texPos]; ASSIGN_4V(tex, 0, 1, 0, 1); tex = v[2]->data[texPos]; ASSIGN_4V(tex, .5, 0, 0, 1); tex = v[3]->data[texPos]; ASSIGN_4V(tex, .5, 1, 0, 1); tex = v[4]->data[texPos]; ASSIGN_4V(tex, .5, 0, 0, 1); tex = v[5]->data[texPos]; ASSIGN_4V(tex, .5, 1, 0, 1); tex = v[6]->data[texPos]; ASSIGN_4V(tex, 1, 0, 0, 1); tex = v[7]->data[texPos]; ASSIGN_4V(tex, 1, 1, 0, 1); /* emit 6 tris for the quad strip */ tri.v[0] = v[2]; tri.v[1] = v[1]; tri.v[2] = v[0]; stage->next->tri( stage->next, &tri ); tri.v[0] = v[3]; tri.v[1] = v[1]; tri.v[2] = v[2]; stage->next->tri( stage->next, &tri ); tri.v[0] = v[4]; tri.v[1] = v[3]; tri.v[2] = v[2]; stage->next->tri( stage->next, &tri ); tri.v[0] = v[5]; tri.v[1] = v[3]; tri.v[2] = v[4]; stage->next->tri( stage->next, &tri ); tri.v[0] = v[6]; tri.v[1] = v[5]; tri.v[2] = v[4]; stage->next->tri( stage->next, &tri ); tri.v[0] = v[7]; tri.v[1] = v[5]; tri.v[2] = v[6]; stage->next->tri( stage->next, &tri ); }