Workaround for images with less channels than the supposed texture format.
This commit is contained in:
parent
5b588fddf1
commit
60a896f513
|
@ -142,6 +142,10 @@ proc loadFileFromSlices*(tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
tex.format
|
tex.format
|
||||||
else:
|
else:
|
||||||
tex.format.resize(min_channels)
|
tex.format.resize(min_channels)
|
||||||
|
# TODO: Don't do this!!
|
||||||
|
# Change the format when the decoder has detected less channels!!
|
||||||
|
let min_channels = format.channel_count
|
||||||
|
|
||||||
let layer_stride = tex.width * tex.height * format.stride
|
let layer_stride = tex.width * tex.height * format.stride
|
||||||
var multilayer_buffer: ArrRef[byte]
|
var multilayer_buffer: ArrRef[byte]
|
||||||
assert tex.depth == slices.len
|
assert tex.depth == slices.len
|
||||||
|
@ -197,8 +201,10 @@ proc loadFileFromSlices*(tex: Texture, slices: seq[SliceMem[byte]],
|
||||||
image = loadFromMemory(slice.toOpenArrayByte, w,h,c, min_channels)
|
image = loadFromMemory(slice.toOpenArrayByte, w,h,c, min_channels)
|
||||||
pixels_ptr = image.data
|
pixels_ptr = image.data
|
||||||
pixels_len = image.len
|
pixels_len = image.len
|
||||||
assert layer_stride == pixels_len,
|
if layer_stride != pixels_len:
|
||||||
&"Image '{tex.name}' has a length of {pixels_len}, expected {layer_stride}"
|
echo "Format: ", format
|
||||||
|
raise Defect.newException &"Image '{tex.name}' has a length" &
|
||||||
|
&" of {pixels_len}, expected {layer_stride}"
|
||||||
if flip:
|
if flip:
|
||||||
swap_lines(pixels_ptr, tex.width * format.stride, tex.height)
|
swap_lines(pixels_ptr, tex.width * format.stride, tex.height)
|
||||||
if tex.depth == 1:
|
if tex.depth == 1:
|
||||||
|
|
Loading…
Reference in a new issue