mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 18:35:59 +08:00
Merge pull request #90 from victorbush/force_32bit_tex
Force default image loader to use 32-bit images
This commit is contained in:
commit
be718436c1
15
tiny_gltf.h
15
tiny_gltf.h
@ -1314,14 +1314,19 @@ bool LoadImageData(Image *image, std::string *err, std::string *warn,
|
|||||||
int size, void *) {
|
int size, void *) {
|
||||||
(void)warn;
|
(void)warn;
|
||||||
|
|
||||||
int w, h, comp;
|
int w, h, comp, req_comp;
|
||||||
|
|
||||||
|
// force 32-bit textures for common Vulkan compatibility. It appears that
|
||||||
|
// some GPU drivers do not support 24-bit images for Vulkan
|
||||||
|
req_comp = 4;
|
||||||
|
|
||||||
// if image cannot be decoded, ignore parsing and keep it by its path
|
// if image cannot be decoded, ignore parsing and keep it by its path
|
||||||
// don't break in this case
|
// don't break in this case
|
||||||
// FIXME we should only enter this function if the image is embedded. If
|
// FIXME we should only enter this function if the image is embedded. If
|
||||||
// image->uri references
|
// image->uri references
|
||||||
// an image file, it should be left as it is. Image loading should not be
|
// an image file, it should be left as it is. Image loading should not be
|
||||||
// mandatory (to support other formats)
|
// mandatory (to support other formats)
|
||||||
unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, 0);
|
unsigned char *data = stbi_load_from_memory(bytes, size, &w, &h, &comp, req_comp);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
// NOTE: you can use `warn` instead of `err`
|
// NOTE: you can use `warn` instead of `err`
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -1360,9 +1365,9 @@ bool LoadImageData(Image *image, std::string *err, std::string *warn,
|
|||||||
|
|
||||||
image->width = w;
|
image->width = w;
|
||||||
image->height = h;
|
image->height = h;
|
||||||
image->component = comp;
|
image->component = req_comp;
|
||||||
image->image.resize(static_cast<size_t>(w * h * comp));
|
image->image.resize(static_cast<size_t>(w * h * req_comp));
|
||||||
std::copy(data, data + w * h * comp, image->image.begin());
|
std::copy(data, data + w * h * req_comp, image->image.begin());
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user