Beispiel #1
0
struct vg_image * image_create(VGImageFormat format,
                               VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct vg_image *image = CALLOC_STRUCT(vg_image);
   enum pipe_format pformat = vg_format_to_pipe(format);
   struct pipe_texture pt, *newtex;
   struct pipe_screen *screen = ctx->pipe->screen;

   vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE);

   image->format = format;
   image->width = width;
   image->height = height;

   image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
   image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
   image->sampler.normalized_coords = 1;

   assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D,
                                      PIPE_TEXTURE_USAGE_SAMPLER, 0));

   memset(&pt, 0, sizeof(pt));
   pt.target = PIPE_TEXTURE_2D;
   pt.format = pformat;
   pt.last_level = 0;
   pt.width0 = width;
   pt.height0 = height;
   pt.depth0 = 1;
   pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;

   newtex = screen->texture_create(screen, &pt);

   debug_assert(newtex);

   image->texture = newtex;

   vg_context_add_object(ctx, VG_OBJECT_IMAGE, image);

   image_cleari(image, 0, 0, 0, image->width, image->height);
   return image;
}
Beispiel #2
0
struct vg_image * image_create(VGImageFormat format,
                               VGint width, VGint height)
{
   struct vg_context *ctx = vg_current_context();
   struct pipe_context *pipe = ctx->pipe;
   struct vg_image *image = CALLOC_STRUCT(vg_image);
   enum pipe_format pformat = vg_format_to_pipe(format);
   struct pipe_resource pt, *newtex;
   struct pipe_sampler_view view_templ;
   struct pipe_sampler_view *view;
   struct pipe_screen *screen = ctx->pipe->screen;

   vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE);

   image->format = format;
   image->width = width;
   image->height = height;

   image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
   image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
   image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST;
   image->sampler.normalized_coords = 1;

   assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D,
                                      0, PIPE_BIND_SAMPLER_VIEW));

   memset(&pt, 0, sizeof(pt));
   pt.target = PIPE_TEXTURE_2D;
   pt.format = pformat;
   pt.last_level = 0;
   pt.width0 = width;
   pt.height0 = height;
   pt.depth0 = 1;
   pt.array_size = 1;
   pt.bind = PIPE_BIND_SAMPLER_VIEW;

   newtex = screen->resource_create(screen, &pt);

   debug_assert(newtex);

   u_sampler_view_default_template(&view_templ, newtex, newtex->format);
   /* R, G, and B are treated as 1.0 for alpha-only formats in OpenVG */
   if (newtex->format == PIPE_FORMAT_A8_UNORM) {
      view_templ.swizzle_r = PIPE_SWIZZLE_ONE;
      view_templ.swizzle_g = PIPE_SWIZZLE_ONE;
      view_templ.swizzle_b = PIPE_SWIZZLE_ONE;
   }

   view = pipe->create_sampler_view(pipe, newtex, &view_templ);
   /* want the texture to go away if the view is freed */
   pipe_resource_reference(&newtex, NULL);

   image->sampler_view = view;

   vg_context_add_object(ctx, &image->base);

   image_cleari(image, 0, 0, 0, image->width, image->height);
   return image;
}