diff options
author | Nicolai Hähnle <[email protected]> | 2016-01-21 16:10:11 -0500 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2016-02-09 10:01:57 -0500 |
commit | c260175677c20ed4f11a6679c45391783d07aaeb (patch) | |
tree | 7ea8b8351a90f3ae00c3653361647551b4377842 /src/gallium/auxiliary | |
parent | 452e51bf1ea6d6896f944192d40547f334f09676 (diff) |
draw: use util_pstipple_* function for stipple pattern textures and samplers
This reduces code duplication.
Suggested-by: Jose Fonseca <[email protected]>
Reviewed-by: Brian Paul <[email protected]>
Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 121 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_pstipple.c | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_pstipple.h | 5 |
3 files changed, 18 insertions, 112 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index e468cc38910..0298334a28f 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -153,113 +153,6 @@ generate_pstip_fs(struct pstip_stage *pstip) /** - * Load texture image with current stipple pattern. - */ -static void -pstip_update_texture(struct pstip_stage *pstip) -{ - static const uint bit31 = 1 << 31; - struct pipe_context *pipe = pstip->pipe; - struct pipe_transfer *transfer; - const uint *stipple = pstip->state.stipple->stipple; - uint i, j; - ubyte *data; - - data = pipe_transfer_map(pipe, pstip->texture, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, 32, 32, &transfer); - - /* - * Load alpha texture. - * Note: 0 means keep the fragment, 255 means kill it. - * We'll negate the texel value and use KILL_IF which kills if value - * is negative. - */ - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - if (stipple[i] & (bit31 >> j)) { - /* fragment "on" */ - data[i * transfer->stride + j] = 0; - } - else { - /* fragment "off" */ - data[i * transfer->stride + j] = 255; - } - } - } - - /* unmap */ - pipe_transfer_unmap(pipe, transfer); -} - - -/** - * Create the texture map we'll use for stippling. - */ -static boolean -pstip_create_texture(struct pstip_stage *pstip) -{ - struct pipe_context *pipe = pstip->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_resource texTemp; - struct pipe_sampler_view viewTempl; - - memset(&texTemp, 0, sizeof(texTemp)); - texTemp.target = PIPE_TEXTURE_2D; - texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */ - texTemp.last_level = 0; - texTemp.width0 = 32; - texTemp.height0 = 32; - texTemp.depth0 = 1; - texTemp.array_size = 1; - texTemp.bind = PIPE_BIND_SAMPLER_VIEW; - - pstip->texture = screen->resource_create(screen, &texTemp); - if (pstip->texture == NULL) - return FALSE; - - u_sampler_view_default_template(&viewTempl, - pstip->texture, - pstip->texture->format); - pstip->sampler_view = pipe->create_sampler_view(pipe, - pstip->texture, - &viewTempl); - if (!pstip->sampler_view) { - return FALSE; - } - - return TRUE; -} - - -/** - * Create the sampler CSO that'll be used for stippling. - */ -static boolean -pstip_create_sampler(struct pstip_stage *pstip) -{ - struct pipe_sampler_state sampler; - struct pipe_context *pipe = pstip->pipe; - - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; - sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; - sampler.wrap_r = PIPE_TEX_WRAP_REPEAT; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.normalized_coords = 1; - sampler.min_lod = 0.0f; - sampler.max_lod = 0.0f; - - pstip->sampler_cso = pipe->create_sampler_state(pipe, &sampler); - if (pstip->sampler_cso == NULL) - return FALSE; - - return TRUE; -} - - -/** * When we're about to draw our first stipple polygon in a batch, this function * is called to tell the driver to bind our modified fragment shader. */ @@ -537,7 +430,8 @@ pstip_set_polygon_stipple(struct pipe_context *pipe, /* pass-through */ pstip->driver_set_polygon_stipple(pstip->pipe, stipple); - pstip_update_texture(pstip); + util_pstipple_update_stipple_texture(pstip->pipe, pstip->texture, + pstip->state.stipple->stipple); } @@ -573,10 +467,17 @@ draw_install_pstipple_stage(struct draw_context *draw, pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; /* create special texture, sampler state */ - if (!pstip_create_texture(pstip)) + 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; - if (!pstip_create_sampler(pstip)) + pstip->sampler_cso = util_pstipple_create_sampler(pipe); + if (!pstip->sampler_cso) goto fail; /* override the driver's functions */ diff --git a/src/gallium/auxiliary/util/u_pstipple.c b/src/gallium/auxiliary/util/u_pstipple.c index 3428172203b..74e6f99da67 100644 --- a/src/gallium/auxiliary/util/u_pstipple.c +++ b/src/gallium/auxiliary/util/u_pstipple.c @@ -58,7 +58,7 @@ #define NUM_NEW_TOKENS 53 -static void +void util_pstipple_update_stipple_texture(struct pipe_context *pipe, struct pipe_resource *tex, const uint32_t pattern[32]) @@ -118,7 +118,7 @@ util_pstipple_create_stipple_texture(struct pipe_context *pipe, tex = screen->resource_create(screen, &templat); - if (tex) + if (tex && pattern) util_pstipple_update_stipple_texture(pipe, tex, pattern); return tex; diff --git a/src/gallium/auxiliary/util/u_pstipple.h b/src/gallium/auxiliary/util/u_pstipple.h index ef8396f4318..d1662be2839 100644 --- a/src/gallium/auxiliary/util/u_pstipple.h +++ b/src/gallium/auxiliary/util/u_pstipple.h @@ -36,6 +36,11 @@ struct pipe_resource; struct pipe_shader_state; +extern void +util_pstipple_update_stipple_texture(struct pipe_context *pipe, + struct pipe_resource *tex, + const uint32_t pattern[32]); + extern struct pipe_resource * util_pstipple_create_stipple_texture(struct pipe_context *pipe, const uint32_t pattern[32]); |