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:
@ -84,9 +84,22 @@ pub fn (mut img Image) init_sokol_image() &Image {
|
||||
label: img.path.str
|
||||
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{
|
||||
ptr: img.data
|
||||
size: usize(img.nr_channels * img.width * img.height)
|
||||
size: img_size
|
||||
}
|
||||
img.simg = gfx.make_image(&img_desc)
|
||||
img.simg_ok = true
|
||||
|
Reference in New Issue
Block a user