Update image::processImage to use compress flag for GLES

This commit is contained in:
Ryan Huffman 2018-07-16 08:47:17 -07:00
parent 9ea08f1850
commit f1e63f489b
2 changed files with 31 additions and 30 deletions

View file

@ -767,22 +767,28 @@ gpu::TexturePointer TextureUsage::process2DTextureColorFromImage(QImage&& srcIma
if ((image.width() > 0) && (image.height() > 0)) {
gpu::Element formatMip;
gpu::Element formatGPU;
if (target == BackendTarget::GLES) {
// GLES does not support GL_BGRA
formatGPU = gpu::Element::COLOR_COMPRESSED_ETC2_SRGBA;
formatMip = formatGPU;
} else if (compress) {
if (validAlpha) {
// NOTE: This disables BC1a compression because it was producing odd artifacts on text textures
// for the tutorial. Instead we use BC3 (which is larger) but doesn't produce the same artifacts).
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_SRGBA;
if (compress) {
if (target == BackendTarget::GLES) {
// GLES does not support GL_BGRA
formatGPU = gpu::Element::COLOR_COMPRESSED_ETC2_SRGBA;
formatMip = formatGPU;
} else {
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_SRGB;
if (validAlpha) {
// NOTE: This disables BC1a compression because it was producing odd artifacts on text textures
// for the tutorial. Instead we use BC3 (which is larger) but doesn't produce the same artifacts).
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_SRGBA;
} else {
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_SRGB;
}
formatMip = formatGPU;
}
formatMip = formatGPU;
} else {
formatGPU = gpu::Element::COLOR_SRGBA_32;
formatMip = gpu::Element::COLOR_SBGRA_32;
if (target == BackendTarget::GLES) {
static_assert(false);
} else {
formatGPU = gpu::Element::COLOR_SRGBA_32;
formatMip = gpu::Element::COLOR_SBGRA_32;
}
}
if (isStrict) {
@ -901,13 +907,13 @@ gpu::TexturePointer TextureUsage::process2DTextureNormalMapFromImage(QImage&& sr
gpu::Element formatMip;
gpu::Element formatGPU;
if (compress) {
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_XY;
} else {
if (target == BackendTarget::GLES) {
formatGPU = gpu::Element::COLOR_COMPRESSED_EAC_XY;
} else {
formatGPU = gpu::Element::VEC2NU8_XY;
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_XY;
}
} else {
formatGPU = gpu::Element::VEC2NU8_XY;
}
formatMip = formatGPU;
@ -941,13 +947,13 @@ gpu::TexturePointer TextureUsage::process2DTextureGrayscaleFromImage(QImage&& sr
gpu::Element formatMip;
gpu::Element formatGPU;
if (compress) {
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_RED;
} else {
if (target == BackendTarget::GLES) {
formatGPU = gpu::Element::COLOR_COMPRESSED_EAC_RED;
} else {
formatGPU = gpu::Element::COLOR_R_8;
}
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_RED;
}
} else {
formatGPU = gpu::Element::COLOR_R_8;
}
formatMip = formatGPU;
@ -1316,14 +1322,15 @@ gpu::TexturePointer TextureUsage::processCubeTextureColorFromImage(QImage&& srcI
gpu::Element formatMip;
gpu::Element formatGPU;
if (compress) {
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_HDR_RGB;
} else {
if (target == BackendTarget::GLES) {
formatGPU = gpu::Element::COLOR_COMPRESSED_ETC2_SRGB;
} else {
formatGPU = HDR_FORMAT;
formatGPU = gpu::Element::COLOR_COMPRESSED_BCX_HDR_RGB;
}
} else {
formatGPU = HDR_FORMAT;
}
formatMip = formatGPU;
// Find the layout of the cubemap in the 2D image

View file

@ -88,13 +88,7 @@ const QStringList getSupportedFormats();
gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& url,
int maxNumPixels, TextureUsage::Type textureType,
bool compress = false,
#ifdef USE_GLES
BackendTarget target = BackendTarget::GLES,
#else
BackendTarget target = BackendTarget::GL,
#endif
const std::atomic<bool>& abortProcessing = false);
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing = false);
} // namespace image