[Mesa-dev] [PATCH] gallium/hud: do .xxxx swizzling for the font texture in the fragment shader
Marek Olšák
maraeo at gmail.com
Mon Apr 1 18:36:50 PDT 2013
This allows using L8 and R8 for the font if I8 isn't supported.
---
src/gallium/auxiliary/hud/hud_context.c | 36 +++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 60355ca..fae7bb1 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -59,7 +59,7 @@ struct hud_context {
/* states */
struct pipe_blend_state alpha_blend;
struct pipe_depth_stencil_alpha_state dsa;
- void *fs_color, *fs_texture;
+ void *fs_color, *fs_text;
struct pipe_rasterizer_state rasterizer;
void *vs;
struct pipe_vertex_element velems[2];
@@ -519,7 +519,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
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_texture);
+ 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);
@@ -890,9 +890,33 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso)
TGSI_SEMANTIC_COLOR,
TGSI_INTERPOLATE_CONSTANT);
- hud->fs_texture =
- util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_RECT,
- TGSI_INTERPOLATE_PERSPECTIVE);
+ {
+ /* Read a texture and do .xxxx swizzling. */
+ static const char *fragment_shader_text = {
+ "FRAG\n"
+ "DCL IN[0], GENERIC[0], LINEAR\n"
+ "DCL SAMP[0]\n"
+ "DCL OUT[0], COLOR[0]\n"
+ "DCL TEMP[0]\n"
+
+ "TEX TEMP[0], IN[0], SAMP[0], RECT\n"
+ "MOV OUT[0], TEMP[0].xxxx\n"
+ "END\n"
+ };
+
+ struct tgsi_token tokens[1000];
+ struct pipe_shader_state state = {tokens};
+
+ if (!tgsi_text_translate(fragment_shader_text, tokens, Elements(tokens))) {
+ assert(0);
+ pipe_resource_reference(&hud->font.texture, NULL);
+ u_upload_destroy(hud->uploader);
+ FREE(hud);
+ return NULL;
+ }
+
+ hud->fs_text = pipe->create_fs_state(pipe, &state);
+ }
/* rasterizer */
hud->rasterizer.gl_rasterization_rules = 1;
@@ -984,7 +1008,7 @@ hud_destroy(struct hud_context *hud)
}
pipe->delete_fs_state(pipe, hud->fs_color);
- pipe->delete_fs_state(pipe, hud->fs_texture);
+ pipe->delete_fs_state(pipe, hud->fs_text);
pipe->delete_vs_state(pipe, hud->vs);
pipe_sampler_view_reference(&hud->font_sampler_view, NULL);
pipe_resource_reference(&hud->font.texture, NULL);
--
1.7.10.4
More information about the mesa-dev
mailing list