gg: allow customisation of the image format in gg.new_streaming_image

pull/10970/head^2
Delyan Angelov 2021-07-26 11:05:16 +03:00
parent 517260a1eb
commit 0d12d55295
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 17 additions and 7 deletions

View File

@ -38,7 +38,7 @@ fn (mut state AppState) draw() {
// gg callbacks: // gg callbacks:
fn graphics_init(mut state AppState) { 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) { fn graphics_frame(mut state AppState) {

View File

@ -185,11 +185,21 @@ pub fn (mut img Image) init_sokol_image() &Image {
return img 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 // 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) // 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. // ... 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. // 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{} mut img := Image{}
img.width = w img.width = w
img.height = h 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{ mut img_desc := C.sg_image_desc{
width: img.width width: img.width
height: img.height height: img.height
pixel_format: .rgba8 pixel_format: sicfg.pixel_format
num_slices: 1 num_slices: 1
num_mipmaps: 1 num_mipmaps: 1
usage: .stream usage: .stream
wrap_u: .clamp_to_edge wrap_u: sicfg.wrap_u
wrap_v: .clamp_to_edge wrap_v: sicfg.wrap_v
min_filter: .linear min_filter: sicfg.min_filter
mag_filter: .linear mag_filter: sicfg.mag_filter
label: img.path.str label: img.path.str
} }
// Sokol requires that streamed images have NO .ptr/.size initially: // Sokol requires that streamed images have NO .ptr/.size initially: