void image_draw(struct vg_image *img, struct matrix *matrix) { struct vg_context *ctx = vg_current_context(); struct matrix paint_matrix; VGfloat x1, y1; VGfloat x2, y2; VGfloat x3, y3; VGfloat x4, y4; if (!vg_get_paint_matrix(ctx, &ctx->state.vg.fill_paint_to_user_matrix, matrix, &paint_matrix)) return; x1 = 0; y1 = 0; x2 = img->width; y2 = 0; x3 = img->width; y3 = img->height; x4 = 0; y4 = img->height; shader_set_surface_matrix(ctx->shader, matrix); shader_set_drawing_image(ctx->shader, VG_TRUE); shader_set_paint(ctx->shader, ctx->state.vg.fill_paint); shader_set_paint_matrix(ctx->shader, &paint_matrix); shader_set_image(ctx->shader, img); shader_bind(ctx->shader); renderer_texture_quad(ctx->renderer, image_texture(img), img->x, img->y, img->x + img->width, img->y + img->height, x1, y1, x2, y2, x3, y3, x4, y4); }
void image_sub_data(struct vg_image *image, const void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height) { const VGint yStep = 1; VGubyte *src = (VGubyte *)data; VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; VGfloat *df = (VGfloat*)temp; VGint i; struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_resource *texture = image_texture(image); VGint xoffset = 0, yoffset = 0; if (x < 0) { xoffset -= x; width += x; x = 0; } if (y < 0) { yoffset -= y; height += y; y = 0; } if (width <= 0 || height <= 0) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (x > image->width || y > image->width) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return; } if (x + width > image->width) { width = image->width - x; } if (y + height > image->height) { height = image->height - y; } { /* upload color_data */ struct pipe_transfer *transfer = pipe_get_transfer( pipe, texture, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0); src += (dataStride * yoffset); for (i = 0; i < height; i++) { _vega_unpack_float_span_rgba(ctx, width, xoffset, src, dataFormat, temp); pipe_put_tile_rgba(pipe, transfer, x+image->x, y+image->y, width, 1, df); y += yStep; src += dataStride; } pipe->transfer_destroy(pipe, transfer); } }
void image_draw(struct vg_image *img) { struct vg_context *ctx = vg_current_context(); VGfloat x1, y1; VGfloat x2, y2; VGfloat x3, y3; VGfloat x4, y4; struct matrix *matrix; x1 = 0; y1 = 0; x2 = img->width; y2 = 0; x3 = img->width; y3 = img->height; x4 = 0; y4 = img->height; matrix = &ctx->state.vg.image_user_to_surface_matrix; matrix_map_point(matrix, x1, y1, &x1, &y1); matrix_map_point(matrix, x2, y2, &x2, &y2); matrix_map_point(matrix, x3, y3, &x3, &y3); matrix_map_point(matrix, x4, y4, &x4, &y4); shader_set_drawing_image(ctx->shader, VG_TRUE); shader_set_paint(ctx->shader, ctx->state.vg.fill_paint); shader_set_image(ctx->shader, img); shader_bind(ctx->shader); renderer_texture_quad(ctx->renderer, image_texture(img), img->x, img->y, img->x + img->width, img->y + img->height, x1, y1, x2, y2, x3, y3, x4, y4); }
void image_set_pixels(VGint dx, VGint dy, struct vg_image *src, VGint sx, VGint sy, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_surface *surf, surf_tmpl; struct st_renderbuffer *strb = ctx->draw_buffer->strb; memset(&surf_tmpl, 0, sizeof(surf_tmpl)); u_surface_default_template(&surf_tmpl, image_texture(src), 0 /* no bind flag - not a surface*/); surf = pipe->create_surface(pipe, image_texture(src), &surf_tmpl); vg_copy_surface(ctx, strb->surface, dx, dy, surf, sx+src->x, sy+src->y, width, height); pipe->surface_destroy(pipe, surf); }
void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_surface *surf, surf_tmpl; struct st_renderbuffer *strb = ctx->draw_buffer->strb; /* flip the y coordinates */ /*dy = dst->height - dy - height;*/ memset(&surf_tmpl, 0, sizeof(surf_tmpl)); u_surface_default_template(&surf_tmpl, image_texture(dst), PIPE_BIND_RENDER_TARGET); surf = pipe->create_surface(pipe, image_texture(dst), &surf_tmpl); vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy, strb->surface, sx, sy, width, height); pipe_surface_reference(&surf, NULL); }
void image_set_pixels(VGint dx, VGint dy, struct vg_image *src, VGint sx, VGint sy, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_surface *surf; struct st_renderbuffer *strb = ctx->draw_buffer->strb; /* make sure rendering has completed */ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); surf = screen->get_tex_surface(screen, image_texture(src), 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); vg_copy_surface(ctx, strb->surface, dx, dy, surf, sx+src->x, sy+src->y, width, height); screen->tex_surface_destroy(surf); }
void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_surface *surf; struct st_renderbuffer *strb = ctx->draw_buffer->strb; /* flip the y coordinates */ /*dy = dst->height - dy - height;*/ /* make sure rendering has completed */ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); surf = screen->get_tex_surface(screen, image_texture(dst), 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE | PIPE_BUFFER_USAGE_GPU_READ); vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy, strb->surface, sx, sy, width, height); pipe_surface_reference(&surf, NULL); }
int start(const std::vector<CL_String> &args) { CL_ConsoleWindow console("Console"); try { CL_DisplayWindow window("Image test", 1024, 768); CL_GraphicContext gc = window.get_gc(); // Connect the Window close event CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_BlendMode blend_mode1; blend_mode1.enable_blending(true); gc.set_blend_mode(blend_mode1); quit = false; CL_ResourceManager resources("resources.xml"); CL_Texture texture(gc, "Images/square.png"); CL_Image image_texture(gc, texture, CL_Rect(0, 0, texture.get_size())); CL_Image image_loaded(gc, "Images/square.png"); CL_Image image_resources(gc, "entire_image", &resources); CL_Image image_copy(image_texture); CL_Image image_top_right(gc, "image_top_right", &resources); CL_Image image_bottom_right(gc, "image_bottom_right", &resources); CL_Image image_black(gc, "image_black", &resources); CL_Font small_font = CL_Font(gc, "Tahoma", 12); //CL_Console::write_line("Color: %1,%2,%3,%4", image_resources.get_color().r, image_resources.get_color().g, image_resources.get_color().b, image_resources.get_color().a); //CL_Console::write_line("Scale: %1,%2", image_resources.get_scale_x(), image_resources.get_scale_y()); //CL_Console::write_line("Translation: %1,%2,%3", image_resources.get_alignment()); while((!quit) && (!window.get_ic().get_keyboard().get_keycode(CL_KEY_ESCAPE))) { gc.clear(CL_Colorf(0.5f,0.5f,0.5f)); small_font.draw_text(gc, 10, 40, "Image From Texture (10,60)"); image_texture.draw(gc, 10, 60); small_font.draw_text(gc, 150, 40, "Image From Load (150,60)"); image_loaded.draw(gc, 150, 60); small_font.draw_text(gc, 300, 40, "Image From Resources (300,60)"); image_resources.draw(gc, 300, 60); small_font.draw_text(gc, 450, 40, "Image Copied (450,60)"); image_copy.draw(gc, 450, 60); small_font.draw_text(gc, 10, 190, "Image - Top Right (10,200)"); image_top_right.draw(gc, 10, 200); small_font.draw_text(gc, 150, 190, "Image - Top Right (150,200)"); image_texture.draw(gc, CL_Rect(32, 0, CL_Size(32, 32)), CL_Rect(150, 200, CL_Size(32, 32))); small_font.draw_text(gc, 300, 190, "Image - Bottom Right (300,200)"); image_bottom_right.draw(gc, 300, 200); small_font.draw_text(gc, 450, 190, "Image - Bottom Right (450,200)"); image_texture.draw(gc, CL_Rect(32, 32, CL_Size(32, 32)), CL_Rect(450, 200, CL_Size(32, 32))); small_font.draw_text(gc, 10, 290, "700 Images (10,300)"); for(int i=0;i<700;i++) image_texture.draw(gc, 10, 300); small_font.draw_text(gc, 150, 290, "br image (150,400) Size(128,256)"); image_bottom_right.draw(gc, CL_Rect(150, 300, CL_Size(128, 256))); small_font.draw_text(gc, 300, 290, "Image - black"); image_black.draw(gc, 300, 300); small_font.draw_text(gc, 300, 490, "Image - Scale (1.5, 2.5)"); image_texture.set_scale(1.5f, 2.5f); image_texture.draw(gc, 300, 500); image_texture.set_scale(1.0f, 1.0f); small_font.draw_text(gc, 450, 460, "Image - Alignment (4 images with 8 pixel offset)"); small_font.draw_text(gc, 450, 475, "(top left, top right, bottom left, bottom right)"); small_font.draw_text(gc, 450, 490, "(Circle denotes the draw origin)"); const int offset = 96; image_texture.set_alignment(origin_top_left, 8, 8); image_texture.draw(gc, 450+offset, 500+offset); image_texture.set_alignment(origin_top_right, -8, 8); image_texture.draw(gc, 450+offset, 500+offset); image_texture.set_alignment(origin_bottom_left, 8, -8); image_texture.draw(gc, 450+offset, 500+offset); image_texture.set_alignment(origin_bottom_right, -8, -8); image_texture.draw(gc, 450+offset, 500+offset); CL_Draw::circle(gc, 450+offset, 500+offset, 4, CL_Colorf(1.0f, 1.0f, 1.0f, 0.9f)); small_font.draw_text(gc, 700, 460, "Image - Center Alignment (4 images with 8 pixel offset)"); small_font.draw_text(gc, 700, 475, "(top center, right center, bottom center, left center)"); small_font.draw_text(gc, 700, 490, "(Circle denotes the draw origin)"); image_texture.set_alignment(origin_top_center, 0, 8); image_texture.draw(gc, 700+offset, 500+offset); image_texture.set_alignment(origin_bottom_center, 0, -8); image_texture.draw(gc, 700+offset, 500+offset); image_texture.set_alignment(origin_center_left, 8, 0); image_texture.draw(gc, 700+offset, 500+offset); image_texture.set_alignment(origin_center_right, -8, 0); image_texture.draw(gc, 700+offset, 500+offset); CL_Draw::circle(gc, 700+offset, 500+offset, 4, CL_Colorf(1.0f, 1.0f, 1.0f, 0.9f)); small_font.draw_text(gc, 700, 160, "Image - Center Align (4 images with 64 pixel offset)"); small_font.draw_text(gc, 700, 175, "Also Includes a centered image (Without offset)"); small_font.draw_text(gc, 700, 190, "(Circle denotes the draw origin)"); const int center_image_offset = 64; image_texture.set_alignment(origin_center, 0, 0); image_texture.draw(gc, 700+offset, 200+offset); image_texture.set_alignment(origin_center, 0, center_image_offset); image_texture.draw(gc, 700+offset, 200+offset); image_texture.set_alignment(origin_center, 0, -center_image_offset); image_texture.draw(gc, 700+offset, 200+offset); image_texture.set_alignment(origin_center, center_image_offset, 0); image_texture.draw(gc, 700+offset, 200+offset); image_texture.set_alignment(origin_center, -center_image_offset, 0); image_texture.draw(gc, 700+offset, 200+offset); CL_Draw::circle(gc, 700+offset, 200+offset, 4, CL_Colorf(1.0f, 1.0f, 1.0f, 0.9f)); // Restore alignment image_texture.set_alignment(origin_top_left, 0, 0); dump_fps(); window.flip(1); CL_KeepAlive::process(); } return 0; } catch(CL_Exception error) { CL_Console::write_line("Exception caught:"); CL_Console::write_line(error.message); console.display_close_message(); return -1; } return 0; }