Bladeren bron

resource: add 'linear' texture setting

Daniele Bartolini 1 maand geleden
bovenliggende
commit
2de123b141

+ 7 - 1
src/resource/texture_resource.cpp

@@ -129,13 +129,15 @@ namespace texture_resource_internal
 		TextureFormat::Enum format; ///< Output format.
 		bool generate_mips;         ///< Whether to generate mip-maps.
 		u32 mip_skip_smallest;      ///< Number of (smallest) mip steps to skip.
-		bool normal_map;            ///< Whether to skip gamma correction.
+		bool normal_map;            ///< Whether the texture is a normal map.
+		bool linear;                ///< Whether to skip gamma correction.
 
 		OutputSettings()
 			: format(TextureFormat::RGBA8)
 			, generate_mips(true)
 			, mip_skip_smallest(0u)
 			, normal_map(false)
+			, linear(false)
 		{
 		}
 	};
@@ -168,6 +170,9 @@ namespace texture_resource_internal
 			if (json_object::has(obj, "normal_map")) {
 				os.normal_map        = RETURN_IF_ERROR(sjson::parse_bool(obj["normal_map"]), opts);
 			}
+			if (json_object::has(obj, "linear")) {
+				os.linear = RETURN_IF_ERROR(sjson::parse_bool(obj["linear"]), opts);
+			}
 		}
 
 		return 0;
@@ -226,6 +231,7 @@ namespace texture_resource_internal
 			"-t",
 			s_texture_formats[os.format].name,
 			(os.normal_map ? "-n" : ""),
+			(os.linear ? "--linear" : ""),
 			(os.generate_mips ? "-m" : ""),
 			(os.mip_skip_smallest > 0 ? "--mipskip" : ""),
 			(os.mip_skip_smallest > 0 ? mipskip : ""),

+ 1 - 1
src/resource/types.h

@@ -97,7 +97,7 @@ struct Platform
 #define RESOURCE_VERSION_SOUND            RESOURCE_VERSION(2)
 #define RESOURCE_VERSION_SPRITE_ANIMATION RESOURCE_VERSION(3)
 #define RESOURCE_VERSION_SPRITE           RESOURCE_VERSION(4)
-#define RESOURCE_VERSION_TEXTURE          RESOURCE_VERSION(11)
+#define RESOURCE_VERSION_TEXTURE          RESOURCE_VERSION(12)
 
 #define RESOURCE_MAGIC                    u32(0x9B) //!< Non-UTF8 to early out on file type detection
 #define RESOURCE_HEADER(version)          u32((version & 0x00ffffff) << 8 | RESOURCE_MAGIC)

+ 15 - 2
tools/level_editor/texture_settings_dialog.vala

@@ -25,6 +25,7 @@ public class TextureSettingsDialog : Gtk.Window
 	public InputBool _generate_mips;
 	public InputDouble _mip_skip_smallest;
 	public InputBool _normal_map;
+	public InputBool _linear;
 	public Gtk.Box _box;
 	public Gtk.EventControllerKey _controller_key;
 	public Gtk.Button _cancel;
@@ -113,12 +114,17 @@ public class TextureSettingsDialog : Gtk.Window
 		_normal_map.value = false;
 		_normal_map.value_changed.connect(on_normal_map_value_changed);
 
+		_linear = new InputBool();
+		_linear.value = false;
+		_linear.value_changed.connect(on_linear_value_changed);
+
 		cv = new PropertyGrid();
 		cv.column_homogeneous = true;
 		cv.add_row("Format", _format);
 		cv.add_row("Generate Mips", _generate_mips);
 		cv.add_row("Skip Smallest Mips", _mip_skip_smallest);
 		cv.add_row("Normal Map", _normal_map);
+		cv.add_row("Linear", _linear);
 		_texture_set.add_property_grid(cv, "Output");
 
 		_stack = new Gtk.Stack();
@@ -256,12 +262,13 @@ public class TextureSettingsDialog : Gtk.Window
 			return;
 		}
 
-		string property_names[] = { "source", "format", "generate_mips", "mip_skip_smallest", "normal_map" };
-		InputField properties[] = { _source, _format, _generate_mips, _mip_skip_smallest, _normal_map };
+		string property_names[] = { "source", "format", "generate_mips", "mip_skip_smallest", "normal_map", "linear" };
+		InputField properties[] = { _source, _format, _generate_mips, _mip_skip_smallest, _normal_map, _linear };
 		_format.value_changed.disconnect(on_format_value_changed);
 		_generate_mips.value_changed.disconnect(on_generate_mips_value_changed);
 		_mip_skip_smallest.value_changed.disconnect(on_mip_skip_smallest_value_changed);
 		_normal_map.value_changed.disconnect(on_normal_map_value_changed);
+		_linear.value_changed.disconnect(on_linear_value_changed);
 
 		for (int i = 0; i < properties.length; ++i)
 			properties[i].set_data("init", false);
@@ -301,6 +308,7 @@ public class TextureSettingsDialog : Gtk.Window
 		_generate_mips.value_changed.connect(on_generate_mips_value_changed);
 		_mip_skip_smallest.value_changed.connect(on_mip_skip_smallest_value_changed);
 		_normal_map.value_changed.connect(on_normal_map_value_changed);
+		_linear.value_changed.connect(on_linear_value_changed);
 	}
 
 	public void on_format_value_changed()
@@ -323,6 +331,11 @@ public class TextureSettingsDialog : Gtk.Window
 		on_property_value_changed("normal_map", _normal_map);
 	}
 
+	public void on_linear_value_changed()
+	{
+		on_property_value_changed("linear", _linear);
+	}
+
 	public void on_property_value_changed(string property_name, InputField property_value)
 	{
 		if (_texture_id == GUID_ZERO)

+ 20 - 0
tools/resource/types.vala

@@ -1452,6 +1452,11 @@ public static void create_object_types(Database database)
 			name = "output.android.normal_map",
 		},
 		PropertyDefinition()
+		{
+			type = PropertyType.BOOL,
+			name = "output.android.linear",
+		},
+		PropertyDefinition()
 		{
 			type = PropertyType.STRING,
 			name = "output.html5.format",
@@ -1476,6 +1481,11 @@ public static void create_object_types(Database database)
 			name = "output.html5.normal_map",
 		},
 		PropertyDefinition()
+		{
+			type = PropertyType.BOOL,
+			name = "output.html5.linear",
+		},
+		PropertyDefinition()
 		{
 			type = PropertyType.STRING,
 			name = "output.linux.format",
@@ -1500,6 +1510,11 @@ public static void create_object_types(Database database)
 			name = "output.linux.normal_map",
 		},
 		PropertyDefinition()
+		{
+			type = PropertyType.BOOL,
+			name = "output.linux.linear",
+		},
+		PropertyDefinition()
 		{
 			type = PropertyType.STRING,
 			name = "output.windows.format",
@@ -1523,6 +1538,11 @@ public static void create_object_types(Database database)
 			type = PropertyType.BOOL,
 			name = "output.windows.normal_map",
 		},
+		PropertyDefinition()
+		{
+			type = PropertyType.BOOL,
+			name = "output.windows.linear",
+		},
 	};
 	database.create_object_type(OBJECT_TYPE_TEXTURE, properties);
 }