[Mesa-dev] [PATCH 1/6] gallium/hud: don't enable blending for all objects
Marek Olšák
maraeo at gmail.com
Thu Aug 18 19:56:28 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/hud/hud_context.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 7870da5..0b292bc 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -57,21 +57,21 @@ static boolean huds_visible = TRUE;
struct hud_context {
struct pipe_context *pipe;
struct cso_context *cso;
struct u_upload_mgr *uploader;
struct hud_batch_query_context *batch_query;
struct list_head pane_list;
/* states */
- struct pipe_blend_state alpha_blend;
+ struct pipe_blend_state no_blend, alpha_blend;
struct pipe_depth_stencil_alpha_state dsa;
void *fs_color, *fs_text;
struct pipe_rasterizer_state rasterizer;
void *vs;
struct pipe_vertex_element velems[2];
/* font */
struct util_font font;
struct pipe_sampler_view *font_sampler_view;
struct pipe_sampler_state font_sampler_state;
@@ -496,21 +496,20 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
viewport.scale[0] = 0.5f * hud->fb_width;
viewport.scale[1] = 0.5f * hud->fb_height;
viewport.scale[2] = 1.0f;
viewport.translate[0] = 0.5f * hud->fb_width;
viewport.translate[1] = 0.5f * hud->fb_height;
viewport.translate[2] = 0.0f;
cso_set_framebuffer(cso, &fb);
cso_set_sample_mask(cso, ~0);
cso_set_min_samples(cso, 1);
- cso_set_blend(cso, &hud->alpha_blend);
cso_set_depth_stencil_alpha(cso, &hud->dsa);
cso_set_rasterizer(cso, &hud->rasterizer);
cso_set_viewport(cso, &viewport);
cso_set_stream_outputs(cso, 0, NULL, NULL);
cso_set_tessctrl_shader_handle(cso, NULL);
cso_set_tesseval_shader_handle(cso, NULL);
cso_set_geometry_shader_handle(cso, NULL);
cso_set_vertex_shader_handle(cso, hud->vs);
cso_set_vertex_elements(cso, 2, hud->velems);
cso_set_render_condition(cso, NULL, FALSE, 0);
@@ -532,59 +531,63 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
gr->query_new_value(gr);
}
hud_pane_accumulate_vertices(hud, pane);
}
/* unmap the uploader's vertex buffer before drawing */
u_upload_unmap(hud->uploader);
/* draw accumulated vertices for background quads */
+ cso_set_blend(cso, &hud->alpha_blend);
cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
if (hud->bg.num_vertices) {
hud->constants.color[0] = 0;
hud->constants.color[1] = 0;
hud->constants.color[2] = 0;
hud->constants.color[3] = 0.666f;
hud->constants.translate[0] = 0;
hud->constants.translate[1] = 0;
hud->constants.scale[0] = 1;
hud->constants.scale[1] = 1;
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
&hud->bg.vbuf);
cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->bg.num_vertices);
}
pipe_resource_reference(&hud->bg.vbuf.buffer, NULL);
/* draw accumulated vertices for white lines */
+ cso_set_blend(cso, &hud->no_blend);
+
hud->constants.color[0] = 1;
hud->constants.color[1] = 1;
hud->constants.color[2] = 1;
hud->constants.color[3] = 1;
hud->constants.translate[0] = 0;
hud->constants.translate[1] = 0;
hud->constants.scale[0] = 1;
hud->constants.scale[1] = 1;
cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
if (hud->whitelines.num_vertices) {
cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
&hud->whitelines.vbuf);
cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
cso_draw_arrays(cso, PIPE_PRIM_LINES, 0, hud->whitelines.num_vertices);
}
pipe_resource_reference(&hud->whitelines.vbuf.buffer, NULL);
/* draw accumulated vertices for text */
+ cso_set_blend(cso, &hud->alpha_blend);
if (hud->text.num_vertices) {
cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
&hud->text.vbuf);
cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
}
pipe_resource_reference(&hud->text.vbuf.buffer, NULL);
/* draw the rest */
LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
@@ -1163,20 +1166,22 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso)
PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM);
/* font */
if (!util_font_create(pipe, UTIL_FONT_FIXED_8X13, &hud->font)) {
u_upload_destroy(hud->uploader);
FREE(hud);
return NULL;
}
/* blend state */
+ hud->no_blend.rt[0].colormask = PIPE_MASK_RGBA;
+
hud->alpha_blend.rt[0].colormask = PIPE_MASK_RGBA;
hud->alpha_blend.rt[0].blend_enable = 1;
hud->alpha_blend.rt[0].rgb_func = PIPE_BLEND_ADD;
hud->alpha_blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
hud->alpha_blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA;
hud->alpha_blend.rt[0].alpha_func = PIPE_BLEND_ADD;
hud->alpha_blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ZERO;
hud->alpha_blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
/* fragment shader */
--
2.7.4
More information about the mesa-dev
mailing list