From 0d12d552958791d509ca77b50d17130ea01c0b22 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 26 Jul 2021 11:05:16 +0300 Subject: [PATCH] gg: allow customisation of the image format in gg.new_streaming_image --- examples/gg/random.v | 2 +- vlib/gg/image.v | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/gg/random.v b/examples/gg/random.v index 55304c8f94..f9e963b849 100644 --- a/examples/gg/random.v +++ b/examples/gg/random.v @@ -38,7 +38,7 @@ fn (mut state AppState) draw() { // gg callbacks: fn graphics_init(mut state AppState) { - state.istream_idx = state.gg.new_streaming_image(pwidth, pheight, pbytes) + state.istream_idx = state.gg.new_streaming_image(pwidth, pheight, pbytes, pixel_format: .rgba8) } fn graphics_frame(mut state AppState) { diff --git a/vlib/gg/image.v b/vlib/gg/image.v index 2ac084b4b4..89a16d7e92 100644 --- a/vlib/gg/image.v +++ b/vlib/gg/image.v @@ -185,11 +185,21 @@ pub fn (mut img Image) init_sokol_image() &Image { return img } +pub struct StreamingImageConfig { + pixel_format gfx.PixelFormat = .rgba8 + wrap_u gfx.Wrap = .clamp_to_edge + wrap_v gfx.Wrap = .clamp_to_edge + min_filter gfx.Filter = .linear + mag_filter gfx.Filter = .linear + num_mipmaps int = 1 + num_slices int = 1 +} + // new_streaming_image returns a cached `image_idx` of a special image, that // can be updated *each frame* by calling: gg.update_pixel_data(image_idx, buf) // ... where buf is a pointer to the actual pixel data for the image. // NB: you still need to call app.gg.draw_image after that, to actually draw it. -pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int) int { +pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int, sicfg StreamingImageConfig) int { mut img := Image{} img.width = w img.height = h @@ -197,14 +207,14 @@ pub fn (mut ctx Context) new_streaming_image(w int, h int, channels int) int { mut img_desc := C.sg_image_desc{ width: img.width height: img.height - pixel_format: .rgba8 + pixel_format: sicfg.pixel_format num_slices: 1 num_mipmaps: 1 usage: .stream - wrap_u: .clamp_to_edge - wrap_v: .clamp_to_edge - min_filter: .linear - mag_filter: .linear + wrap_u: sicfg.wrap_u + wrap_v: sicfg.wrap_v + min_filter: sicfg.min_filter + mag_filter: sicfg.mag_filter label: img.path.str } // Sokol requires that streamed images have NO .ptr/.size initially: