Sfoglia il codice sorgente

resource: prevent generating invalid render states

Daniele Bartolini 6 anni fa
parent
commit
9bea8cf466
3 ha cambiato i file con 13 aggiunte e 9 eliminazioni
  1. 1 0
      CHANGELOG.md
  2. 11 8
      src/resource/shader_resource.cpp
  3. 1 1
      src/resource/types.h

+ 1 - 0
CHANGELOG.md

@@ -25,6 +25,7 @@ Changelog
 * tools: fixed an issue that caused the Level Editor to not correctly save a level specified from command line
 * tools: fixed an issue that caused the Level Editor to not correctly save a level specified from command line
 * tools: fixed an issue that could cause the Level Editor to crash when large number of TCP/IP packets were sent to it
 * tools: fixed an issue that could cause the Level Editor to crash when large number of TCP/IP packets were sent to it
 * tools: fixed an issue that could cause the Level Editor to incorreclty parse identifiers in SJSON files
 * tools: fixed an issue that could cause the Level Editor to incorreclty parse identifiers in SJSON files
+* tools: fixed an issue that generated wrong render states when blending is enabled while no blend funtion/equation is specified
 * tools: fixed an issue that prevented some operations in the Level Editor from being (un/re)done
 * tools: fixed an issue that prevented some operations in the Level Editor from being (un/re)done
 * tools: fixed an issue that prevented the data compiler from restoring and saving its state when launched by the Level Editor
 * tools: fixed an issue that prevented the data compiler from restoring and saving its state when launched by the Level Editor
 * tools: the Data Compiler will now track data "requirements" and automatically include them in packages when it's needed
 * tools: the Data Compiler will now track data "requirements" and automatically include them in packages when it's needed

+ 11 - 8
src/resource/shader_resource.cpp

@@ -103,6 +103,7 @@ namespace shader_resource_internal
 	{
 	{
 		enum Enum
 		enum Enum
 		{
 		{
+			PT_TRIANGLES,
 			PT_TRISTRIP,
 			PT_TRISTRIP,
 			PT_LINES,
 			PT_LINES,
 			PT_LINESTRIP,
 			PT_LINESTRIP,
@@ -216,6 +217,7 @@ namespace shader_resource_internal
 
 
 	static const PrimitiveTypeInfo _primitive_type_map[] =
 	static const PrimitiveTypeInfo _primitive_type_map[] =
 	{
 	{
+		{ "pt_triangles", PrimitiveType::PT_TRIANGLES },
 		{ "pt_tristrip",  PrimitiveType::PT_TRISTRIP  },
 		{ "pt_tristrip",  PrimitiveType::PT_TRISTRIP  },
 		{ "pt_lines",     PrimitiveType::PT_LINES     },
 		{ "pt_lines",     PrimitiveType::PT_LINES     },
 		{ "pt_linestrip", PrimitiveType::PT_LINESTRIP },
 		{ "pt_linestrip", PrimitiveType::PT_LINESTRIP },
@@ -301,6 +303,7 @@ namespace shader_resource_internal
 
 
 	static const u64 _bgfx_primitive_type_map[] =
 	static const u64 _bgfx_primitive_type_map[] =
 	{
 	{
+		0,                       // PrimitiveType::PT_TRIANGLES
 		BGFX_STATE_PT_TRISTRIP,  // PrimitiveType::PT_TRISTRIP
 		BGFX_STATE_PT_TRISTRIP,  // PrimitiveType::PT_TRISTRIP
 		BGFX_STATE_PT_LINES,     // PrimitiveType::PT_LINES
 		BGFX_STATE_PT_LINES,     // PrimitiveType::PT_LINES
 		BGFX_STATE_PT_LINESTRIP, // PrimitiveType::PT_LINESTRIP
 		BGFX_STATE_PT_LINESTRIP, // PrimitiveType::PT_LINESTRIP
@@ -485,12 +488,12 @@ namespace shader_resource_internal
 			_depth_write_enable = false;
 			_depth_write_enable = false;
 			_depth_enable = false;
 			_depth_enable = false;
 			_blend_enable = false;
 			_blend_enable = false;
-			_depth_func = DepthFunction::COUNT;
-			_blend_src = BlendFunction::COUNT;
-			_blend_dst = BlendFunction::COUNT;
-			_blend_equation = BlendEquation::COUNT;
-			_cull_mode = CullMode::COUNT;
-			_primitive_type = PrimitiveType::COUNT;
+			_depth_func = DepthFunction::LEQUAL;
+			_blend_src = BlendFunction::SRC_ALPHA;
+			_blend_dst = BlendFunction::INV_SRC_ALPHA;
+			_blend_equation = BlendEquation::ADD;
+			_cull_mode = CullMode::CW;
+			_primitive_type = PrimitiveType::PT_TRIANGLES;
 		}
 		}
 
 
 		u64 encode() const
 		u64 encode() const
@@ -499,11 +502,11 @@ namespace shader_resource_internal
 				? _bgfx_depth_func_map[_depth_func]
 				? _bgfx_depth_func_map[_depth_func]
 				: 0
 				: 0
 				;
 				;
-			const u64 blend_func = _blend_enable
+			const u64 blend_func = _blend_enable && _blend_src != BlendFunction::COUNT && _blend_dst != BlendFunction::COUNT
 				? BGFX_STATE_BLEND_FUNC(_bgfx_blend_func_map[_blend_src], _bgfx_blend_func_map[_blend_dst])
 				? BGFX_STATE_BLEND_FUNC(_bgfx_blend_func_map[_blend_src], _bgfx_blend_func_map[_blend_dst])
 				: 0
 				: 0
 				;
 				;
-			const u64 blend_eq = _blend_enable
+			const u64 blend_eq = _blend_enable && _blend_equation != BlendEquation::COUNT
 				? BGFX_STATE_BLEND_EQUATION(_bgfx_blend_equation_map[_blend_equation])
 				? BGFX_STATE_BLEND_EQUATION(_bgfx_blend_equation_map[_blend_equation])
 				: 0
 				: 0
 				;
 				;

+ 1 - 1
src/resource/types.h

@@ -65,7 +65,7 @@ struct UnitResource;
 #define RESOURCE_VERSION_PACKAGE          RESOURCE_VERSION(4)
 #define RESOURCE_VERSION_PACKAGE          RESOURCE_VERSION(4)
 #define RESOURCE_VERSION_PHYSICS_CONFIG   RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_PHYSICS_CONFIG   RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SCRIPT           RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SCRIPT           RESOURCE_VERSION(1)
-#define RESOURCE_VERSION_SHADER           RESOURCE_VERSION(1)
+#define RESOURCE_VERSION_SHADER           RESOURCE_VERSION(2)
 #define RESOURCE_VERSION_SOUND            RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SOUND            RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SPRITE_ANIMATION RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SPRITE_ANIMATION RESOURCE_VERSION(1)
 #define RESOURCE_VERSION_SPRITE           RESOURCE_VERSION(2)
 #define RESOURCE_VERSION_SPRITE           RESOURCE_VERSION(2)