mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: always use 4 channels in init_sokol_image (#16564)
This commit is contained in:
parent
161847ed1a
commit
6e24f7e13a
@ -84,9 +84,22 @@ pub fn (mut img Image) init_sokol_image() &Image {
|
|||||||
label: img.path.str
|
label: img.path.str
|
||||||
d3d11_texture: 0
|
d3d11_texture: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE the following code, sometimes, result in hard-to-detect visual errors/bugs:
|
||||||
|
// img_size := usize(img.nr_channels * img.width * img.height)
|
||||||
|
// As an example see https://github.com/vlang/vab/issues/239
|
||||||
|
// The image will come out blank for some reason and no SOKOL_ASSERT
|
||||||
|
// nor any CI check will/can currently catch this.
|
||||||
|
// Since all of gg currently runs with more or less *defaults* from sokol_gfx/sokol_gl
|
||||||
|
// we should currently just use the sum of each of the RGB and A channels (= 4) here instead.
|
||||||
|
// Optimized PNG images that have no alpha channel is often optimized to only have
|
||||||
|
// 3 (or less) channels which stbi will correctly detect and set as `img.nr_channels`
|
||||||
|
// but the current sokol_gl context setup expects 4. It *should* be the same with
|
||||||
|
// all other stbi supported formats.
|
||||||
|
img_size := usize(4 * img.width * img.height)
|
||||||
img_desc.data.subimage[0][0] = gfx.Range{
|
img_desc.data.subimage[0][0] = gfx.Range{
|
||||||
ptr: img.data
|
ptr: img.data
|
||||||
size: usize(img.nr_channels * img.width * img.height)
|
size: img_size
|
||||||
}
|
}
|
||||||
img.simg = gfx.make_image(&img_desc)
|
img.simg = gfx.make_image(&img_desc)
|
||||||
img.simg_ok = true
|
img.simg_ok = true
|
||||||
|
@ -117,14 +117,9 @@ pub fn load(path string) !Image {
|
|||||||
ext: ext
|
ext: ext
|
||||||
data: 0
|
data: 0
|
||||||
}
|
}
|
||||||
// flag := if ext == 'png' { C.STBI_rgb_alpha } else { 0 }
|
|
||||||
desired_channels := if ext in ['png', 'jpg', 'jpeg'] { 4 } else { 0 }
|
|
||||||
res.data = C.stbi_load(&char(path.str), &res.width, &res.height, &res.nr_channels,
|
res.data = C.stbi_load(&char(path.str), &res.width, &res.height, &res.nr_channels,
|
||||||
desired_channels)
|
C.STBI_rgb_alpha)
|
||||||
if desired_channels == 4 && res.nr_channels == 3 {
|
|
||||||
// Fix an alpha png bug
|
|
||||||
res.nr_channels = 4
|
|
||||||
}
|
|
||||||
if isnil(res.data) {
|
if isnil(res.data) {
|
||||||
return error('stbi_image failed to load from "${path}"')
|
return error('stbi_image failed to load from "${path}"')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user