u_blit.c File Reference

Copy/blit pixel rect between surfaces. More...

Include dependency graph for u_blit.c:

Go to the source code of this file.

Data Structures

struct  blit_state

Functions

struct blit_stateutil_create_blit (struct pipe_context *pipe, struct cso_context *cso)
 Create state object for blit.
void util_destroy_blit (struct blit_state *ctx)
 Destroy a blit context.
static unsigned get_next_slot (struct blit_state *ctx)
static unsigned setup_vertex_data (struct blit_state *ctx, float x0, float y0, float x1, float y1, float z)
 Setup vertex data for the textured quad we'll draw.
static unsigned setup_vertex_data_tex (struct blit_state *ctx, float x0, float y0, float x1, float y1, float s0, float t0, float s1, float t1, float z)
 Setup vertex data for the textured quad we'll draw.
void util_blit_pixels (struct blit_state *ctx, struct pipe_surface *src, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, int dstX0, int dstY0, int dstX1, int dstY1, float z, uint filter)
 Copy pixel block from src surface to dst surface.
void util_blit_flush (struct blit_state *ctx)
void util_blit_pixels_tex (struct blit_state *ctx, struct pipe_texture *tex, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, int dstX0, int dstY0, int dstX1, int dstY1, float z, uint filter)
 Copy pixel block from src texture to dst surface.


Detailed Description

Copy/blit pixel rect between surfaces.

Author:
Brian Paul

Definition in file u_blit.c.


Function Documentation

static unsigned get_next_slot ( struct blit_state ctx  )  [static]

Definition at line 176 of file u_blit.c.

References blit_state::pipe, pipe_buffer_create(), PIPE_BUFFER_USAGE_VERTEX, pipe_context::screen, util_blit_flush(), blit_state::vbuf, blit_state::vbuf_slot, and blit_state::vertices.

00177 {
00178    const unsigned max_slots = 4096 / sizeof ctx->vertices;
00179 
00180    if (ctx->vbuf_slot >= max_slots) 
00181       util_blit_flush( ctx );
00182 
00183    if (!ctx->vbuf) {
00184       ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
00185                                      32,
00186                                      PIPE_BUFFER_USAGE_VERTEX,
00187                                      max_slots * sizeof ctx->vertices);
00188    }
00189    
00190    return ctx->vbuf_slot++ * sizeof ctx->vertices;
00191 }

static unsigned setup_vertex_data ( struct blit_state ctx,
float  x0,
float  y0,
float  x1,
float  y1,
float  z 
) [static]

Setup vertex data for the textured quad we'll draw.

Note: y=0=top

Definition at line 200 of file u_blit.c.

References get_next_slot(), offset(), blit_state::pipe, pipe_buffer_map(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CPU_WRITE, pipe_context::screen, blit_state::vbuf, and blit_state::vertices.

00202 {
00203    void *buf;
00204    unsigned offset;
00205 
00206    ctx->vertices[0][0][0] = x0;
00207    ctx->vertices[0][0][1] = y0;
00208    ctx->vertices[0][0][2] = z;
00209    ctx->vertices[0][1][0] = 0.0f; /*s*/
00210    ctx->vertices[0][1][1] = 0.0f; /*t*/
00211 
00212    ctx->vertices[1][0][0] = x1;
00213    ctx->vertices[1][0][1] = y0;
00214    ctx->vertices[1][0][2] = z;
00215    ctx->vertices[1][1][0] = 1.0f; /*s*/
00216    ctx->vertices[1][1][1] = 0.0f; /*t*/
00217 
00218    ctx->vertices[2][0][0] = x1;
00219    ctx->vertices[2][0][1] = y1;
00220    ctx->vertices[2][0][2] = z;
00221    ctx->vertices[2][1][0] = 1.0f;
00222    ctx->vertices[2][1][1] = 1.0f;
00223 
00224    ctx->vertices[3][0][0] = x0;
00225    ctx->vertices[3][0][1] = y1;
00226    ctx->vertices[3][0][2] = z;
00227    ctx->vertices[3][1][0] = 0.0f;
00228    ctx->vertices[3][1][1] = 1.0f;
00229 
00230    offset = get_next_slot( ctx );
00231 
00232    buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf,
00233                          PIPE_BUFFER_USAGE_CPU_WRITE);
00234 
00235    memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices));
00236 
00237    pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf);
00238 
00239    return offset;
00240 }

static unsigned setup_vertex_data_tex ( struct blit_state ctx,
float  x0,
float  y0,
float  x1,
float  y1,
float  s0,
float  t0,
float  s1,
float  t1,
float  z 
) [static]

Setup vertex data for the textured quad we'll draw.

Note: y=0=top

Definition at line 248 of file u_blit.c.

References get_next_slot(), offset(), blit_state::pipe, pipe_buffer_map(), pipe_buffer_unmap(), PIPE_BUFFER_USAGE_CPU_WRITE, pipe_context::screen, blit_state::vbuf, and blit_state::vertices.

00252 {
00253    void *buf;
00254    unsigned offset;
00255 
00256    ctx->vertices[0][0][0] = x0;
00257    ctx->vertices[0][0][1] = y0;
00258    ctx->vertices[0][0][2] = z;
00259    ctx->vertices[0][1][0] = s0; /*s*/
00260    ctx->vertices[0][1][1] = t0; /*t*/
00261 
00262    ctx->vertices[1][0][0] = x1;
00263    ctx->vertices[1][0][1] = y0;
00264    ctx->vertices[1][0][2] = z;
00265    ctx->vertices[1][1][0] = s1; /*s*/
00266    ctx->vertices[1][1][1] = t0; /*t*/
00267 
00268    ctx->vertices[2][0][0] = x1;
00269    ctx->vertices[2][0][1] = y1;
00270    ctx->vertices[2][0][2] = z;
00271    ctx->vertices[2][1][0] = s1;
00272    ctx->vertices[2][1][1] = t1;
00273 
00274    ctx->vertices[3][0][0] = x0;
00275    ctx->vertices[3][0][1] = y1;
00276    ctx->vertices[3][0][2] = z;
00277    ctx->vertices[3][1][0] = s0;
00278    ctx->vertices[3][1][1] = t1;
00279 
00280    offset = get_next_slot( ctx );
00281 
00282    buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf,
00283                          PIPE_BUFFER_USAGE_CPU_WRITE);
00284 
00285    memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices));
00286 
00287    pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf);
00288 
00289    return offset;
00290 }

void util_blit_flush ( struct blit_state ctx  ) 

Definition at line 450 of file u_blit.c.

References blit_state::pipe, pipe_buffer_reference(), pipe_context::screen, blit_state::vbuf, and blit_state::vbuf_slot.

00451 {
00452    pipe_buffer_reference(ctx->pipe->screen, &ctx->vbuf, NULL);
00453    ctx->vbuf_slot = 0;
00454 } 

void util_blit_pixels ( struct blit_state ctx,
struct pipe_surface src,
int  srcX0,
int  srcY0,
int  srcX1,
int  srcY1,
struct pipe_surface dst,
int  dstX0,
int  dstY0,
int  dstX1,
int  dstY1,
float  z,
uint  filter 
)

Copy pixel block from src surface to dst surface.

Overlapping regions are acceptable. XXX need some control over blitting Z and/or stencil.

Definition at line 297 of file u_blit.c.

References abs(), assert, blit_state::blend, pipe_texture::block, pipe_framebuffer_state::cbufs, pipe_texture::compressed, blit_state::cso, cso_restore_blend(), cso_restore_depth_stencil_alpha(), cso_restore_fragment_shader(), cso_restore_framebuffer(), cso_restore_rasterizer(), cso_restore_sampler_textures(), cso_restore_samplers(), cso_restore_vertex_shader(), cso_restore_viewport(), cso_save_blend(), cso_save_depth_stencil_alpha(), cso_save_fragment_shader(), cso_save_framebuffer(), cso_save_rasterizer(), cso_save_sampler_textures(), cso_save_samplers(), cso_save_vertex_shader(), cso_save_viewport(), cso_set_blend(), cso_set_depth_stencil_alpha(), cso_set_fragment_shader_handle(), cso_set_framebuffer(), cso_set_rasterizer(), cso_set_sampler_textures(), cso_set_vertex_shader_handle(), cso_set_viewport(), cso_single_sampler(), cso_single_sampler_done(), pipe_texture::depth, blit_state::depthstencil, FALSE, pipe_texture::format, pipe_surface::format, blit_state::fs, pipe_screen::get_tex_surface, pipe_surface::height, pipe_framebuffer_state::height, pipe_texture::height, pipe_screen::is_format_supported, pipe_texture::last_level, pipe_sampler_state::mag_img_filter, MIN2, pipe_sampler_state::min_img_filter, pipe_framebuffer_state::num_cbufs, offset(), pf_get_block(), blit_state::pipe, PIPE_BUFFER_USAGE_GPU_WRITE, PIPE_PRIM_TRIANGLE_FAN, PIPE_TEX_MIPFILTER_LINEAR, PIPE_TEX_MIPFILTER_NEAREST, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, PIPE_TEXTURE_USAGE_SAMPLER, blit_state::rasterizer, blit_state::sampler, pipe_context::screen, setup_vertex_data(), pipe_context::surface_copy, pipe_texture::target, pipe_screen::tex_surface_release, pipe_screen::texture_create, pipe_screen::texture_release, util_draw_vertex_buffer(), blit_state::vbuf, blit_state::viewport, blit_state::vs, pipe_surface::width, pipe_framebuffer_state::width, and pipe_texture::width.

00305 {
00306    struct pipe_context *pipe = ctx->pipe;
00307    struct pipe_screen *screen = pipe->screen;
00308    struct pipe_texture texTemp, *tex;
00309    struct pipe_surface *texSurf;
00310    struct pipe_framebuffer_state fb;
00311    const int srcW = abs(srcX1 - srcX0);
00312    const int srcH = abs(srcY1 - srcY0);
00313    const int srcLeft = MIN2(srcX0, srcX1);
00314    const int srcTop = MIN2(srcY0, srcY1);
00315    unsigned offset;
00316 
00317    assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
00318           filter == PIPE_TEX_MIPFILTER_LINEAR);
00319 
00320    if (srcLeft != srcX0) {
00321       /* left-right flip */
00322       int tmp = dstX0;
00323       dstX0 = dstX1;
00324       dstX1 = tmp;
00325    }
00326 
00327    if (srcTop != srcY0) {
00328       /* up-down flip */
00329       int tmp = dstY0;
00330       dstY0 = dstY1;
00331       dstY1 = tmp;
00332    }
00333 
00334    assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
00335                                       PIPE_TEXTURE_USAGE_SAMPLER, 0));
00336    assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
00337                                       PIPE_TEXTURE_USAGE_SAMPLER, 0));
00338 
00339    if(dst->format == src->format && (dstX1 - dstX0) == srcW && (dstY1 - dstY0) == srcH) {
00340       /* FIXME: this will most surely fail for overlapping rectangles */
00341       pipe->surface_copy(pipe, FALSE,
00342                          dst, dstX0, dstY0,   /* dest */
00343                          src, srcX0, srcY0, /* src */
00344                          srcW, srcH);     /* size */
00345       return;
00346    }
00347    
00348    assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
00349                                       PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
00350 
00351    /*
00352     * XXX for now we're always creating a temporary texture.
00353     * Strictly speaking that's not always needed.
00354     */
00355 
00356    /* create temp texture */
00357    memset(&texTemp, 0, sizeof(texTemp));
00358    texTemp.target = PIPE_TEXTURE_2D;
00359    texTemp.format = src->format;
00360    texTemp.last_level = 0;
00361    texTemp.width[0] = srcW;
00362    texTemp.height[0] = srcH;
00363    texTemp.depth[0] = 1;
00364    texTemp.compressed = 0;
00365    pf_get_block(src->format, &texTemp.block);
00366 
00367    tex = screen->texture_create(screen, &texTemp);
00368    if (!tex)
00369       return;
00370 
00371    texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, 
00372                                      PIPE_BUFFER_USAGE_GPU_WRITE);
00373 
00374    /* load temp texture */
00375    pipe->surface_copy(pipe, FALSE,
00376                       texSurf, 0, 0,   /* dest */
00377                       src, srcLeft, srcTop, /* src */
00378                       srcW, srcH);     /* size */
00379 
00380    /* free the surface, update the texture if necessary.
00381     */
00382    screen->tex_surface_release(screen, &texSurf);
00383 
00384    /* save state (restored below) */
00385    cso_save_blend(ctx->cso);
00386    cso_save_depth_stencil_alpha(ctx->cso);
00387    cso_save_rasterizer(ctx->cso);
00388    cso_save_samplers(ctx->cso);
00389    cso_save_sampler_textures(ctx->cso);
00390    cso_save_framebuffer(ctx->cso);
00391    cso_save_fragment_shader(ctx->cso);
00392    cso_save_vertex_shader(ctx->cso);
00393    cso_save_viewport(ctx->cso);
00394 
00395    /* set misc state we care about */
00396    cso_set_blend(ctx->cso, &ctx->blend);
00397    cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
00398    cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
00399    cso_set_viewport(ctx->cso, &ctx->viewport);
00400 
00401    /* sampler */
00402    ctx->sampler.min_img_filter = filter;
00403    ctx->sampler.mag_img_filter = filter;
00404    cso_single_sampler(ctx->cso, 0, &ctx->sampler);
00405    cso_single_sampler_done(ctx->cso);
00406 
00407    /* texture */
00408    cso_set_sampler_textures(ctx->cso, 1, &tex);
00409 
00410    /* shaders */
00411    cso_set_fragment_shader_handle(ctx->cso, ctx->fs);
00412    cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
00413 
00414    /* drawing dest */
00415    memset(&fb, 0, sizeof(fb));
00416    fb.width = dst->width;
00417    fb.height = dst->height;
00418    fb.num_cbufs = 1;
00419    fb.cbufs[0] = dst;
00420    cso_set_framebuffer(ctx->cso, &fb);
00421 
00422    /* draw quad */
00423    offset = setup_vertex_data(ctx,
00424                               (float) dstX0, (float) dstY0, 
00425                               (float) dstX1, (float) dstY1, z);
00426 
00427    util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, offset,
00428                            PIPE_PRIM_TRIANGLE_FAN,
00429                            4,  /* verts */
00430                            2); /* attribs/vert */
00431 
00432    /* restore state we changed */
00433    cso_restore_blend(ctx->cso);
00434    cso_restore_depth_stencil_alpha(ctx->cso);
00435    cso_restore_rasterizer(ctx->cso);
00436    cso_restore_samplers(ctx->cso);
00437    cso_restore_sampler_textures(ctx->cso);
00438    cso_restore_framebuffer(ctx->cso);
00439    cso_restore_fragment_shader(ctx->cso);
00440    cso_restore_vertex_shader(ctx->cso);
00441    cso_restore_viewport(ctx->cso);
00442 
00443    screen->texture_release(screen, &tex);
00444 }

void util_blit_pixels_tex ( struct blit_state ctx,
struct pipe_texture tex,
int  srcX0,
int  srcY0,
int  srcX1,
int  srcY1,
struct pipe_surface dst,
int  dstX0,
int  dstY0,
int  dstX1,
int  dstY1,
float  z,
uint  filter 
)

Copy pixel block from src texture to dst surface.

Overlapping regions are acceptable.

XXX Should support selection of level. XXX need some control over blitting Z and/or stencil.

Definition at line 466 of file u_blit.c.

References assert, blit_state::blend, pipe_framebuffer_state::cbufs, blit_state::cso, cso_restore_blend(), cso_restore_depth_stencil_alpha(), cso_restore_fragment_shader(), cso_restore_framebuffer(), cso_restore_rasterizer(), cso_restore_sampler_textures(), cso_restore_samplers(), cso_restore_vertex_shader(), cso_restore_viewport(), cso_save_blend(), cso_save_depth_stencil_alpha(), cso_save_fragment_shader(), cso_save_framebuffer(), cso_save_rasterizer(), cso_save_sampler_textures(), cso_save_samplers(), cso_save_vertex_shader(), cso_save_viewport(), cso_set_blend(), cso_set_depth_stencil_alpha(), cso_set_fragment_shader_handle(), cso_set_framebuffer(), cso_set_rasterizer(), cso_set_sampler_textures(), cso_set_vertex_shader_handle(), cso_set_viewport(), cso_single_sampler(), cso_single_sampler_done(), blit_state::depthstencil, pipe_surface::format, blit_state::fs, pipe_surface::height, pipe_framebuffer_state::height, pipe_texture::height, pipe_screen::is_format_supported, pipe_sampler_state::mag_img_filter, pipe_sampler_state::min_img_filter, pipe_framebuffer_state::num_cbufs, offset(), blit_state::pipe, PIPE_PRIM_TRIANGLE_FAN, PIPE_TEX_MIPFILTER_LINEAR, PIPE_TEX_MIPFILTER_NEAREST, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, blit_state::rasterizer, blit_state::sampler, pipe_context::screen, setup_vertex_data_tex(), util_draw_vertex_buffer(), blit_state::vbuf, blit_state::viewport, blit_state::vs, pipe_surface::width, pipe_framebuffer_state::width, and pipe_texture::width.

00474 {
00475    struct pipe_context *pipe = ctx->pipe;
00476    struct pipe_screen *screen = pipe->screen;
00477    struct pipe_framebuffer_state fb;
00478    float s0, t0, s1, t1;
00479    unsigned offset;
00480 
00481    assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
00482           filter == PIPE_TEX_MIPFILTER_LINEAR);
00483 
00484    assert(tex->width[0] != 0);
00485    assert(tex->height[0] != 0);
00486 
00487    s0 = srcX0 / (float)tex->width[0];
00488    s1 = srcX1 / (float)tex->width[0];
00489    t0 = srcY0 / (float)tex->height[0];
00490    t1 = srcY1 / (float)tex->height[0];
00491 
00492    assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
00493                                       PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
00494 
00495    /* save state (restored below) */
00496    cso_save_blend(ctx->cso);
00497    cso_save_depth_stencil_alpha(ctx->cso);
00498    cso_save_rasterizer(ctx->cso);
00499    cso_save_samplers(ctx->cso);
00500    cso_save_sampler_textures(ctx->cso);
00501    cso_save_framebuffer(ctx->cso);
00502    cso_save_fragment_shader(ctx->cso);
00503    cso_save_vertex_shader(ctx->cso);
00504    cso_save_viewport(ctx->cso);
00505 
00506    /* set misc state we care about */
00507    cso_set_blend(ctx->cso, &ctx->blend);
00508    cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil);
00509    cso_set_rasterizer(ctx->cso, &ctx->rasterizer);
00510    cso_set_viewport(ctx->cso, &ctx->viewport);
00511 
00512    /* sampler */
00513    ctx->sampler.min_img_filter = filter;
00514    ctx->sampler.mag_img_filter = filter;
00515    cso_single_sampler(ctx->cso, 0, &ctx->sampler);
00516    cso_single_sampler_done(ctx->cso);
00517 
00518    /* texture */
00519    cso_set_sampler_textures(ctx->cso, 1, &tex);
00520 
00521    /* shaders */
00522    cso_set_fragment_shader_handle(ctx->cso, ctx->fs);
00523    cso_set_vertex_shader_handle(ctx->cso, ctx->vs);
00524 
00525    /* drawing dest */
00526    memset(&fb, 0, sizeof(fb));
00527    fb.width = dst->width;
00528    fb.height = dst->height;
00529    fb.num_cbufs = 1;
00530    fb.cbufs[0] = dst;
00531    cso_set_framebuffer(ctx->cso, &fb);
00532 
00533    /* draw quad */
00534    offset = setup_vertex_data_tex(ctx,
00535                                   (float) dstX0, (float) dstY0,
00536                                   (float) dstX1, (float) dstY1,
00537                                   s0, t0, s1, t1,
00538                                   z);
00539 
00540    util_draw_vertex_buffer(ctx->pipe, 
00541                            ctx->vbuf, offset,
00542                            PIPE_PRIM_TRIANGLE_FAN,
00543                            4,  /* verts */
00544                            2); /* attribs/vert */
00545 
00546    /* restore state we changed */
00547    cso_restore_blend(ctx->cso);
00548    cso_restore_depth_stencil_alpha(ctx->cso);
00549    cso_restore_rasterizer(ctx->cso);
00550    cso_restore_samplers(ctx->cso);
00551    cso_restore_sampler_textures(ctx->cso);
00552    cso_restore_framebuffer(ctx->cso);
00553    cso_restore_fragment_shader(ctx->cso);
00554    cso_restore_vertex_shader(ctx->cso);
00555    cso_restore_viewport(ctx->cso);
00556 }

struct blit_state* util_create_blit ( struct pipe_context pipe,
struct cso_context cso 
) [read]

Create state object for blit.

Intended to be created once and re-used for many blit() calls.

Definition at line 80 of file u_blit.c.

References pipe_blend_state::alpha_dst_factor, pipe_blend_state::alpha_src_factor, blit_state::blend, pipe_rasterizer_state::bypass_clipping, CALLOC_STRUCT, pipe_blend_state::colormask, blit_state::cso, pipe_rasterizer_state::cull_mode, blit_state::depthstencil, blit_state::frag_shader, pipe_rasterizer_state::front_winding, blit_state::fs, pipe_rasterizer_state::gl_rasterization_rules, pipe_sampler_state::mag_img_filter, pipe_sampler_state::min_img_filter, pipe_sampler_state::min_mip_filter, pipe_sampler_state::normalized_coords, blit_state::pipe, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ZERO, PIPE_MASK_RGBA, PIPE_TEX_MIPFILTER_NONE, PIPE_TEX_WRAP_CLAMP_TO_EDGE, PIPE_WINDING_CW, PIPE_WINDING_NONE, blit_state::rasterizer, pipe_blend_state::rgb_dst_factor, pipe_blend_state::rgb_src_factor, blit_state::sampler, pipe_viewport_state::scale, semantic_names, TGSI_SEMANTIC_GENERIC, TGSI_SEMANTIC_POSITION, pipe_viewport_state::translate, util_make_fragment_tex_shader(), util_make_vertex_passthrough_shader(), blit_state::vbuf, blit_state::vert_shader, blit_state::vertices, blit_state::viewport, blit_state::vs, pipe_sampler_state::wrap_r, pipe_sampler_state::wrap_s, and pipe_sampler_state::wrap_t.

00081 {
00082    struct blit_state *ctx;
00083    uint i;
00084 
00085    ctx = CALLOC_STRUCT(blit_state);
00086    if (!ctx)
00087       return NULL;
00088 
00089    ctx->pipe = pipe;
00090    ctx->cso = cso;
00091 
00092    /* disabled blending/masking */
00093    memset(&ctx->blend, 0, sizeof(ctx->blend));
00094    ctx->blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
00095    ctx->blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
00096    ctx->blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
00097    ctx->blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
00098    ctx->blend.colormask = PIPE_MASK_RGBA;
00099 
00100    /* no-op depth/stencil/alpha */
00101    memset(&ctx->depthstencil, 0, sizeof(ctx->depthstencil));
00102 
00103    /* rasterizer */
00104    memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer));
00105    ctx->rasterizer.front_winding = PIPE_WINDING_CW;
00106    ctx->rasterizer.cull_mode = PIPE_WINDING_NONE;
00107    ctx->rasterizer.bypass_clipping = 1;
00108    /*ctx->rasterizer.bypass_vs = 1;*/
00109    ctx->rasterizer.gl_rasterization_rules = 1;
00110 
00111    /* samplers */
00112    memset(&ctx->sampler, 0, sizeof(ctx->sampler));
00113    ctx->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00114    ctx->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00115    ctx->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
00116    ctx->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
00117    ctx->sampler.min_img_filter = 0; /* set later */
00118    ctx->sampler.mag_img_filter = 0; /* set later */
00119    ctx->sampler.normalized_coords = 1;
00120 
00121    /* viewport (identity, we setup vertices in wincoords) */
00122    ctx->viewport.scale[0] = 1.0;
00123    ctx->viewport.scale[1] = 1.0;
00124    ctx->viewport.scale[2] = 1.0;
00125    ctx->viewport.scale[3] = 1.0;
00126    ctx->viewport.translate[0] = 0.0;
00127    ctx->viewport.translate[1] = 0.0;
00128    ctx->viewport.translate[2] = 0.0;
00129    ctx->viewport.translate[3] = 0.0;
00130 
00131    /* vertex shader */
00132    {
00133       const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
00134                                       TGSI_SEMANTIC_GENERIC };
00135       const uint semantic_indexes[] = { 0, 0 };
00136       ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
00137                                                     semantic_indexes,
00138                                                     &ctx->vert_shader);
00139    }
00140 
00141    /* fragment shader */
00142    ctx->fs = util_make_fragment_tex_shader(pipe, &ctx->frag_shader);
00143    ctx->vbuf = NULL;
00144 
00145    /* init vertex data that doesn't change */
00146    for (i = 0; i < 4; i++) {
00147       ctx->vertices[i][0][3] = 1.0f; /* w */
00148       ctx->vertices[i][1][2] = 0.0f; /* r */
00149       ctx->vertices[i][1][3] = 1.0f; /* q */
00150    }
00151 
00152    return ctx;
00153 }

void util_destroy_blit ( struct blit_state ctx  ) 

Destroy a blit context.

Definition at line 160 of file u_blit.c.

References pipe_context::delete_fs_state, pipe_context::delete_vs_state, blit_state::frag_shader, FREE, blit_state::fs, blit_state::pipe, pipe_buffer_reference(), pipe_context::screen, pipe_shader_state::tokens, blit_state::vbuf, blit_state::vert_shader, and blit_state::vs.

00161 {
00162    struct pipe_context *pipe = ctx->pipe;
00163 
00164    pipe->delete_vs_state(pipe, ctx->vs);
00165    pipe->delete_fs_state(pipe, ctx->fs);
00166 
00167    FREE((void*) ctx->vert_shader.tokens);
00168    FREE((void*) ctx->frag_shader.tokens);
00169 
00170    pipe_buffer_reference(pipe->screen, &ctx->vbuf, NULL);
00171 
00172    FREE(ctx);
00173 }


Generated on Tue Sep 29 06:25:27 2009 for Gallium3D by  doxygen 1.5.4