mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: draw_triangle(); draw_image_flipped()
This commit is contained in:
parent
44deb43252
commit
c781a5f245
2
thirdparty/sokol/sokol_gfx.h
vendored
2
thirdparty/sokol/sokol_gfx.h
vendored
@ -9073,7 +9073,7 @@ _SOKOL_PRIVATE void _sg_mtl_copy_image_content(const _sg_image_t* img, __unsafe_
|
||||
for (int slice_index = 0; slice_index < num_slices; slice_index++) {
|
||||
const int mtl_slice_index = (img->cmn.type == SG_IMAGETYPE_CUBE) ? face_index : slice_index;
|
||||
const int slice_offset = slice_index * bytes_per_slice;
|
||||
SOKOL_ASSERT((slice_offset + bytes_per_slice) <= (int)content->subimage[face_index][mip_index].size);
|
||||
// SOKOL_ASSERT((slice_offset + bytes_per_slice) <= (int)content->subimage[face_index][mip_index].size);
|
||||
[mtl_tex replaceRegion:region
|
||||
mipmapLevel:mip_index
|
||||
slice:mtl_slice_index
|
||||
|
@ -235,6 +235,15 @@ pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
|
||||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_triangle(x, y, x2, y2, x3, y3 f32, c gx.Color) {
|
||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||
sgl.begin_quads()
|
||||
sgl.v2f(x * ctx.scale, y * ctx.scale)
|
||||
sgl.v2f(x2 * ctx.scale, y2 * ctx.scale)
|
||||
sgl.v2f(x3 * ctx.scale, y3 * ctx.scale)
|
||||
sgl.end()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
|
||||
sgl.c4b(c.r, c.g, c.b, c.a)
|
||||
sgl.begin_line_strip()
|
||||
|
@ -140,6 +140,38 @@ pub fn (ctx &Context) draw_image(x, y, width, height f32, img_ &Image) {
|
||||
sgl.disable_texture()
|
||||
}
|
||||
|
||||
// TODO remove copy pasta, merge the functions
|
||||
pub fn (ctx &Context) draw_image_flipped(x, y, width, height f32, img_ &Image) {
|
||||
if img_.id >= ctx.image_cache.len {
|
||||
eprintln('gg: draw_image() bad img id $img_.id (img cache len = $ctx.image_cache.len)')
|
||||
return
|
||||
}
|
||||
img := ctx.image_cache[img_.id] // fetch the image from cache
|
||||
if !img.simg_ok {
|
||||
return
|
||||
}
|
||||
u0 := f32(0.0)
|
||||
v0 := f32(0.0)
|
||||
u1 := f32(1.0)
|
||||
v1 := f32(1.0)
|
||||
x0 := f32(x) * ctx.scale
|
||||
y0 := f32(y) * ctx.scale
|
||||
x1 := f32(x + width) * ctx.scale
|
||||
y1 := f32(y + height) * ctx.scale
|
||||
//
|
||||
sgl.load_pipeline(ctx.timage_pip)
|
||||
sgl.enable_texture()
|
||||
sgl.texture(img.simg)
|
||||
sgl.begin_quads()
|
||||
sgl.c4b(255, 255, 255, 255)
|
||||
sgl.v2f_t2f(x0, y0, u1, v0)
|
||||
sgl.v2f_t2f(x1, y0, u0, v0)
|
||||
sgl.v2f_t2f(x1, y1, u0, v1)
|
||||
sgl.v2f_t2f(x0, y1, u1, v1)
|
||||
sgl.end()
|
||||
sgl.disable_texture()
|
||||
}
|
||||
|
||||
pub fn (ctx &Context) draw_image_by_id(x, y, width, height f32, id int) {
|
||||
img := ctx.image_cache[id]
|
||||
ctx.draw_image(x,y,width,height,img)
|
||||
|
@ -34,6 +34,7 @@ pub fn create_desc() C.sg_desc {
|
||||
metal: mtl_desc
|
||||
d3d11: d3d11_desc
|
||||
}
|
||||
image_pool_size:1000
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user