Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid texture profile configuration #6579

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions com.dynamo.cr/com.dynamo.cr.bob/src/com/dynamo/bob/Bob.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@ private static Options getCommandLineOptions() {
addOption(options, "mp", "mobileprovisioning", true, "mobileprovisioning profile (iOS)", false);
addOption(options, null, "identity", true, "Sign identity (iOS)", false);

addOption(options, "ce", "certificate", true, "DEPRECATED! Certificate (Android)", false);
addOption(options, "pk", "private-key", true, "DEPRECATED! Private key (Android)", false);

addOption(options, "ks", "keystore", true, "Deployment keystore used to sign APKs (Android)", false);
addOption(options, "ksp", "keystore-pass", true, "Pasword of the deployment keystore (Android)", false);
addOption(options, "ksa", "keystore-alias", true, "The alias of the signing key+cert you want to use (Android)", false);
Expand All @@ -435,8 +432,7 @@ private static Options getCommandLineOptions() {
addOption(options, null, "strip-executable", false, "Strip the dmengine of debug symbols (when bundling iOS or Android)", false);
addOption(options, null, "with-symbols", false, "Generate the symbol file (if applicable)", false);

addOption(options, "tp", "texture-profiles", true, "Use texture profiles (deprecated)", true);
addOption(options, "tc", "texture-compression", true, "Use texture compression as specified in texture profiles", true);
addOption(options, "tc", "texture-compression", true, "Use texture compression as specified in texture profiles (true|false)", true);
addOption(options, "k", "keep-unused", false, "Keep unused resources in archived output", true);

addOption(options, null, "exclude-build-folder", true, "Comma separated list of folders to exclude from the build", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public interface CompressionLevel {
}

public interface CompressionType {
public static int CT_DEFAULT = 0;
public static int CT_DEFAULT = 0; // Deprecated in favor of NONE
public static int CT_BASIS_UASTC= 3;
public static int CT_BASIS_ETC1S= 4;
public static int CT_NONE = 5;
}

public enum FlipAxis {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.EnumSet;

import javax.imageio.ImageIO;

import com.dynamo.bob.Bob;
import com.dynamo.bob.TexcLibrary;
import com.dynamo.bob.TexcLibrary.ColorSpace;
import com.dynamo.bob.TexcLibrary.DitherType;
Expand All @@ -61,26 +63,57 @@

public class TextureGenerator {

private static HashMap<TextureFormatAlternative.CompressionLevel, Integer> compressionLevelLUT = new HashMap<TextureFormatAlternative.CompressionLevel, Integer>();
private static Logger logger = Logger.getLogger(TextureGenerator.class.getName());

private static HashMap<TextureFormatAlternative.CompressionLevel, Integer> compressionLevelLUT = new HashMap<>();
static {
compressionLevelLUT.put(TextureFormatAlternative.CompressionLevel.FAST, CompressionLevel.CL_FAST);
compressionLevelLUT.put(TextureFormatAlternative.CompressionLevel.NORMAL, CompressionLevel.CL_NORMAL);
compressionLevelLUT.put(TextureFormatAlternative.CompressionLevel.HIGH, CompressionLevel.CL_HIGH);
compressionLevelLUT.put(TextureFormatAlternative.CompressionLevel.BEST, CompressionLevel.CL_BEST);
}

private static HashMap<TextureImage.CompressionType, Integer> compressionTypeLUT = new HashMap<TextureImage.CompressionType, Integer>();
private static HashMap<TextureImage.CompressionType, Integer> compressionTypeLUT = new HashMap<>();
static {
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT, CompressionType.CT_DEFAULT);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT, CompressionType.CT_NONE);
// For backwards compatibility, we automatically convert the WEBP to either DEFAULT, or UASTC
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_WEBP, CompressionType.CT_DEFAULT);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_WEBP, CompressionType.CT_NONE);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_WEBP_LOSSY, CompressionType.CT_BASIS_UASTC);

compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_UASTC, CompressionType.CT_BASIS_UASTC);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_ETC1S, CompressionType.CT_BASIS_ETC1S);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_ETC1S, CompressionType.CT_BASIS_UASTC);
compressionTypeLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_NONE, CompressionType.CT_NONE);
}

private static HashSet<TextureFormat> supportedFormatsForNone = new HashSet<>();
static {
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_LUMINANCE);
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_RGB);
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_RGBA);
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_RGB_16BPP);
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_RGBA_16BPP);
supportedFormatsForNone.add(TextureFormat.TEXTURE_FORMAT_LUMINANCE_ALPHA);
}
private static HashSet<TextureFormat> supportedFormatsForUASTC = new HashSet<>();
static {
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_LUMINANCE);
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_RGB);
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_RGBA);
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_RGB_16BPP);
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_RGBA_16BPP);
supportedFormatsForUASTC.add(TextureFormat.TEXTURE_FORMAT_LUMINANCE_ALPHA);
}

private static HashMap<TextureFormat, Integer> pixelFormatLUT = new HashMap<TextureFormat, Integer>();
private static HashMap<TextureImage.CompressionType, HashSet<TextureFormat>> supportedFormatsLUT = new HashMap<>();
static {
supportedFormatsLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT, new HashSet<>());
supportedFormatsLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_NONE, supportedFormatsForNone);
supportedFormatsLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_UASTC, supportedFormatsForUASTC);
supportedFormatsLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_WEBP, new HashSet<>());
supportedFormatsLUT.put(TextureImage.CompressionType.COMPRESSION_TYPE_WEBP_LOSSY, new HashSet<>());
}

private static HashMap<TextureFormat, Integer> pixelFormatLUT = new HashMap<>();
static {
pixelFormatLUT.put(TextureFormat.TEXTURE_FORMAT_LUMINANCE, PixelFormat.L8);
pixelFormatLUT.put(TextureFormat.TEXTURE_FORMAT_RGB, PixelFormat.R8G8B8);
Expand Down Expand Up @@ -231,27 +264,40 @@ private static TextureImage.Image generateFromColorAndFormat(String name, Buffer

int dataSize = width * height * 4;


ByteBuffer buffer_input = getByteBuffer(image);

// convert unsupported compression types
if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_WEBP) {
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_NONE;
logger.log(Level.WARNING, "Lossless WebP compression is not supported. Using no compression.");
}
else if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_WEBP_LOSSY) {
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_UASTC;
logger.log(Level.WARNING, "Lossy WebP compression is not supported. Using Basis UASTC.");
}
else if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_ETC1S) {
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_UASTC;
logger.log(Level.WARNING, "Basis ETC1S compression is not supported. Using Basis UASTC.");
}
else if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT) {
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_NONE;
}

HashSet<TextureFormat> supportedFormats = supportedFormatsLUT.get(compressionType);
if (!supportedFormats.contains(textureFormat)) {
throw new TextureGeneratorException("Unsupported texture format '" + textureFormat + "' for compression '" + compressionType + "'");
}

// convert from protobuf specified compressionlevel to texc int
texcCompressionLevel = compressionLevelLUT.get(compressionLevel);

// convert compression type from WebP to something else
if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_WEBP)
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT;
else
if (compressionType == TextureImage.CompressionType.COMPRESSION_TYPE_WEBP_LOSSY)
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_BASIS_UASTC;

// convert from protobuf specified compressionType to texc int
texcCompressionType = compressionTypeLUT.get(compressionType);

if (!compress) {
texcCompressionLevel = CompressionLevel.CL_FAST;
texcCompressionType = CompressionType.CT_DEFAULT;
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT;
texcCompressionType = CompressionType.CT_NONE;
compressionType = TextureImage.CompressionType.COMPRESSION_TYPE_NONE;

// If pvrtc or etc1, set these as rgba instead. Since these formats will take some time to compress even
// with "fast" setting and we don't want to increase the build time more than we have to.
Expand Down Expand Up @@ -309,7 +355,6 @@ private static TextureImage.Image generateFromColorAndFormat(String name, Buffer
textureFormat == TextureFormat.TEXTURE_FORMAT_RGB_PVRTC_2BPPV1 ||
textureFormat == TextureFormat.TEXTURE_FORMAT_RGBA_PVRTC_2BPPV1)) {

Logger logger = Logger.getLogger(TextureGenerator.class.getName());
logger.log(Level.WARNING, "PVR compressed texture is not square and will be resized.");

newWidth = Math.max(newWidth, newHeight);
Expand Down Expand Up @@ -455,6 +500,7 @@ public static TextureImage generate(BufferedImage origImage, TextureProfile texP
// Generate an image for each format specified in the profile
for (PlatformProfile platformProfile : texProfile.getPlatformsList()) {
for (int i = 0; i < platformProfile.getFormatsList().size(); ++i) {
Bob.verbose("generate with texture profile i: %d", i);
TextureImage.CompressionType compressionType = platformProfile.getFormats(i).getCompressionType();
TextureFormatAlternative.CompressionLevel compressionLevel = platformProfile.getFormats(i).getCompressionLevel();
TextureFormat textureFormat = platformProfile.getFormats(i).getFormat();
Expand Down Expand Up @@ -485,7 +531,7 @@ public static TextureImage generate(BufferedImage origImage, TextureProfile texP

// Guess texture format based on number color components of input image
TextureFormat textureFormat = pickOptimalFormat(componentCount, TextureFormat.TEXTURE_FORMAT_RGBA);
TextureImage.Image raw = generateFromColorAndFormat(null, image, colorModel, textureFormat, TextureFormatAlternative.CompressionLevel.NORMAL, TextureImage.CompressionType.COMPRESSION_TYPE_DEFAULT, true, 0, false, true, flipAxis);
TextureImage.Image raw = generateFromColorAndFormat(null, image, colorModel, textureFormat, TextureFormatAlternative.CompressionLevel.NORMAL, TextureImage.CompressionType.COMPRESSION_TYPE_NONE, true, 0, false, true, flipAxis);
textureBuilder.addAlternatives(raw);
textureBuilder.setCount(1);

Expand Down
6 changes: 3 additions & 3 deletions editor/src/clj/editor/texture/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(def CL_HIGH TexcLibrary$CompressionLevel/CL_HIGH)
(def CL_BEST TexcLibrary$CompressionLevel/CL_BEST)

(def CT_DEFAULT TexcLibrary$CompressionType/CT_DEFAULT)
(def CT_NONE TexcLibrary$CompressionType/CT_NONE)

(def TEXTURE_FORMAT_LUMINANCE Graphics$TextureImage$TextureFormat/TEXTURE_FORMAT_LUMINANCE)
(def TEXTURE_FORMAT_RGB Graphics$TextureImage$TextureFormat/TEXTURE_FORMAT_RGB)
Expand Down Expand Up @@ -118,7 +118,7 @@
color-count (image-color-components img)
[pixel-format texture-format] (get formats color-count default-formats)
name nil ; for easier debugging
texture (TexcLibrary/TEXC_Create name, width height R8G8B8A8 SRGB CT_DEFAULT (image->byte-buffer img))
texture (TexcLibrary/TEXC_Create name, width height R8G8B8A8 SRGB CT_NONE (image->byte-buffer img))
compression-level Graphics$TextureFormatAlternative$CompressionLevel/FAST
mipmaps false]

Expand All @@ -127,7 +127,7 @@
(resize texture width height width-pot height-pot) "could not resize texture to POT"
(premultiply-alpha texture) "could not premultiply alpha"
(gen-mipmaps texture) "could not generate mip-maps"
(transcode texture pixel-format SRGB compression-level CT_DEFAULT mipmaps) "could not transcode")
(transcode texture pixel-format SRGB compression-level CT_NONE mipmaps) "could not transcode")
(let [buffer-size (* width-pot height-pot color-count 2)
buffer (little-endian (new-byte-buffer buffer-size))
data-size (TexcLibrary/TEXC_GetData texture buffer buffer-size)
Expand Down
2 changes: 1 addition & 1 deletion engine/gamesys/src/gamesys/scripts/script_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ static int SetTexture(lua_State* L)
image->m_OriginalWidth = width;
image->m_OriginalHeight = height;
image->m_Format = (dmGraphics::TextureImage::TextureFormat)GraphicsTextureFormatToImageFormat(format);
image->m_CompressionType = dmGraphics::TextureImage::COMPRESSION_TYPE_DEFAULT;
image->m_CompressionType = dmGraphics::TextureImage::COMPRESSION_TYPE_NONE;
image->m_CompressionFlags = 0;
image->m_Data.m_Data = data;
image->m_Data.m_Count = datasize;
Expand Down
19 changes: 13 additions & 6 deletions engine/graphics/proto/graphics/graphics_ddf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ message TextureImage

enum CompressionType
{
// Not compressed
// Deprecated, converts to NONE
COMPRESSION_TYPE_DEFAULT = 0;
// WebP encoded (Deprecated, converts to Default)

// Not supported. Converts to Default
COMPRESSION_TYPE_WEBP = 1;
// WebP lossy encoded (Deprecated, converts to UASTC)

// Not supported. Converts to Basis UASTC
COMPRESSION_TYPE_WEBP_LOSSY = 2;

// Basis UASTC
COMPRESSION_TYPE_BASIS_UASTC = 3;
// Basis ETC1S

// Not supported. Converts to Basis UASTC
COMPRESSION_TYPE_BASIS_ETC1S = 4;

// Not compressed
COMPRESSION_TYPE_NONE = 5;
}

enum CompressionFlags
Expand Down Expand Up @@ -81,7 +88,7 @@ message TextureImage
repeated uint32 mip_map_offset = 6;
repeated uint32 mip_map_size = 7; // always uncompressed (native) size
required bytes data = 8;
optional CompressionType compression_type = 9 [default = COMPRESSION_TYPE_DEFAULT];
optional CompressionType compression_type = 9 [default = COMPRESSION_TYPE_NONE];
optional uint64 compression_flags = 10;
repeated uint32 mip_map_size_compressed = 11;
}
Expand All @@ -107,7 +114,7 @@ message TextureFormatAlternative

required TextureImage.TextureFormat format = 1;
required CompressionLevel compression_level = 2;
optional TextureImage.CompressionType compression_type = 3 [default = COMPRESSION_TYPE_DEFAULT];
optional TextureImage.CompressionType compression_type = 3 [default = COMPRESSION_TYPE_NONE];
}

message PathSettings
Expand Down
18 changes: 9 additions & 9 deletions engine/texc/src/test/test_texc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ uint16_t default_data_rgba_4444[4] =

static dmTexc::HTexture CreateDefaultRGBA16(dmTexc::CompressionType compression_type)
{
return dmTexc::Create(0, 2, 2, dmTexc::PF_R4G4B4A4, dmTexc::CS_LRGB, dmTexc::CT_DEFAULT, default_data_rgba_4444);
return dmTexc::Create(0, 2, 2, dmTexc::PF_R4G4B4A4, dmTexc::CS_LRGB, dmTexc::CT_NONE, default_data_rgba_4444);
}


Expand All @@ -119,12 +119,12 @@ struct Format
};
Format formats[] =
{
{CreateDefaultL8, 1, default_data_l, dmTexc::CT_DEFAULT, dmTexc::PF_L8},
{CreateDefaultL8A8, 2, default_data_l8a8, dmTexc::CT_DEFAULT, dmTexc::PF_L8A8},
{CreateDefaultRGB24, 3, default_data_rgb_888, dmTexc::CT_DEFAULT, dmTexc::PF_R8G8B8},
{CreateDefaultRGBA32, 4, default_data_rgba_8888, dmTexc::CT_DEFAULT, dmTexc::PF_R8G8B8A8},
{CreateDefaultRGB16, 2, default_data_rgb_565, dmTexc::CT_DEFAULT, dmTexc::PF_R5G6B5},
{CreateDefaultRGBA16, 2, default_data_rgba_4444, dmTexc::CT_DEFAULT, dmTexc::PF_R4G4B4A4},
{CreateDefaultL8, 1, default_data_l, dmTexc::CT_NONE, dmTexc::PF_L8},
{CreateDefaultL8A8, 2, default_data_l8a8, dmTexc::CT_NONE, dmTexc::PF_L8A8},
{CreateDefaultRGB24, 3, default_data_rgb_888, dmTexc::CT_NONE, dmTexc::PF_R8G8B8},
{CreateDefaultRGBA32, 4, default_data_rgba_8888, dmTexc::CT_NONE, dmTexc::PF_R8G8B8A8},
{CreateDefaultRGB16, 2, default_data_rgb_565, dmTexc::CT_NONE, dmTexc::PF_R5G6B5},
{CreateDefaultRGBA16, 2, default_data_rgba_4444, dmTexc::CT_NONE, dmTexc::PF_R4G4B4A4},
};
static const size_t format_count = sizeof(formats)/sizeof(Format);

Expand Down Expand Up @@ -253,7 +253,7 @@ TEST_F(TexcTest, FlipAxis)
const uint8_t white[4] = {255, 255, 255, 255};

uint8_t out[4*4];
dmTexc::HTexture texture = CreateDefaultRGBA32(dmTexc::CT_DEFAULT);
dmTexc::HTexture texture = CreateDefaultRGBA32(dmTexc::CT_NONE);

// Original values
dmTexc::GetData(texture, out, 16);
Expand Down Expand Up @@ -442,7 +442,7 @@ struct CompileInfo
};
CompileInfo compile_info[] =
{
{"src/test/data/a.png", dmTexc::CT_DEFAULT, dmTexc::PF_R8G8B8A8, dmTexc::PF_R5G6B5, dmTexc::CS_SRGB},
{"src/test/data/a.png", dmTexc::CT_NONE, dmTexc::PF_R8G8B8A8, dmTexc::PF_R5G6B5, dmTexc::CS_SRGB},
};

class TexcCompileTest : public jc_test_params_class<CompileInfo>
Expand Down
1 change: 1 addition & 0 deletions engine/texc/src/texc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace dmTexc
{
case dmTexc::CT_BASIS_UASTC:
case dmTexc::CT_BASIS_ETC1S: GetEncoderBasis(encoder); return true;
case dmTexc::CT_NONE:
case dmTexc::CT_DEFAULT: GetEncoderDefault(encoder); return true;
default:
return false;
Expand Down
7 changes: 4 additions & 3 deletions engine/texc/src/texc.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ namespace dmTexc
enum CompressionType
{
CT_DEFAULT, // == NONE
CT_WEBP, // Deprecated
CT_WEBP_LOSSY, // Deprecated
CT_WEBP, // Not supported
CT_WEBP_LOSSY, // Not supported
CT_BASIS_UASTC,
CT_BASIS_ETC1S,
CT_BASIS_ETC1S, // Not supported
CT_NONE,
};

enum CompressionFlags
Expand Down