From 428f6a06ad4550e14aa0f6befb7848cd1c0e91f7 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 22 Jan 2017 16:36:35 +0100
Subject: [PATCH] Added patch to implement some more wined3d blend modes.

---
 patches/patchinstall.sh                       | 86 ++++++++++++-------
 .../0001-wined3d-Add-more-blend-modes.patch   | 47 ++++++++++
 patches/wined3d-Blend_Factor/definition       |  2 +
 .../wined3d-CSMT_Main/9999-IfDefined.patch    | 28 +++---
 staging/VERSION                               |  2 +-
 5 files changed, 120 insertions(+), 45 deletions(-)
 create mode 100644 patches/wined3d-Blend_Factor/0001-wined3d-Add-more-blend-modes.patch
 create mode 100644 patches/wined3d-Blend_Factor/definition

diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh
index 40b92110..91c944e6 100755
--- a/patches/patchinstall.sh
+++ b/patches/patchinstall.sh
@@ -58,7 +58,7 @@ upstream_commit()
 # Show version information
 version()
 {
-	echo "Wine Staging 2.0-rc6"
+	echo "Wine Staging 2.0-rc7 (unreleased)"
 	echo "Copyright (C) 2014-2017 the Wine Staging project authors."
 	echo ""
 	echo "Patchset to be applied on upstream Wine:"
@@ -401,6 +401,7 @@ patch_enable_all ()
 	enable_winecfg_Unmounted_Devices="$1"
 	enable_wined3d_1DTextures="$1"
 	enable_wined3d_Accounting="$1"
+	enable_wined3d_Blend_Factor="$1"
 	enable_wined3d_CSMT_Helper="$1"
 	enable_wined3d_CSMT_Main="$1"
 	enable_wined3d_DXTn="$1"
@@ -1425,6 +1426,9 @@ patch_enable ()
 		wined3d-Accounting)
 			enable_wined3d_Accounting="$2"
 			;;
+		wined3d-Blend_Factor)
+			enable_wined3d_Blend_Factor="$2"
+			;;
 		wined3d-CSMT_Helper)
 			enable_wined3d_CSMT_Helper="$2"
 			;;
@@ -2222,6 +2226,13 @@ if test "$enable_wined3d_CSMT_Helper" -eq 1; then
 	enable_wined3d_Silence_FIXMEs=1
 fi
 
+if test "$enable_wined3d_Blend_Factor" -eq 1; then
+	if test "$enable_wined3d_Silence_FIXMEs" -gt 1; then
+		abort "Patchset wined3d-Silence_FIXMEs disabled, but wined3d-Blend_Factor depends on that."
+	fi
+	enable_wined3d_Silence_FIXMEs=1
+fi
+
 if test "$enable_wineboot_ProxySettings" -eq 1; then
 	if test "$enable_wineboot_DriveSerial" -gt 1; then
 		abort "Patchset wineboot-DriveSerial disabled, but wineboot-ProxySettings depends on that."
@@ -8433,6 +8444,50 @@ if test "$enable_wined3d_Accounting" -eq 1; then
 	) >> "$patchlist"
 fi
 
+# Patchset wined3d-Silence_FIXMEs
+# |
+# | This patchset fixes the following Wine bugs:
+# |   *	[#42140] Silence noisy FIXME in gl_stencil_op
+# |
+# | Modified files:
+# |   *	dlls/wined3d/resource.c, dlls/wined3d/state.c, dlls/wined3d/surface.c, dlls/wined3d/swapchain.c, dlls/wined3d/texture.c
+# |
+if test "$enable_wined3d_Silence_FIXMEs" -eq 1; then
+	patch_apply wined3d-Silence_FIXMEs/0001-wined3d-Silence-repeated-Unhandled-blend-factor-0-me.patch
+	patch_apply wined3d-Silence_FIXMEs/0002-wined3d-Display-FIXME-for-cmp-function-0-only-once.patch
+	patch_apply wined3d-Silence_FIXMEs/0003-wined3d-Silence-repeated-resource_check_usage-FIXME.patch
+	patch_apply wined3d-Silence_FIXMEs/0004-wined3d-Print-FIXME-only-once-in-surface_cpu_blt.patch
+	patch_apply wined3d-Silence_FIXMEs/0005-wined3d-Silence-repeated-wined3d_swapchain_present-F.patch
+	patch_apply wined3d-Silence_FIXMEs/0006-wined3d-Silence-extremely-noisy-FIXME-in-wined3d_tex.patch
+	patch_apply wined3d-Silence_FIXMEs/0007-wined3d-Display-FIXME-only-once-when-blen-op-is-0.patch
+	patch_apply wined3d-Silence_FIXMEs/0008-wined3d-Silence-noisy-fixme-Unrecognized-stencil-op-.patch
+	(
+		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence repeated '\''Unhandled blend factor 0'\'' messages.", 1 },';
+		printf '%s\n' '+    { "Christian Costa", "wined3d: Display FIXME for cmp function 0 only once.", 1 },';
+		printf '%s\n' '+    { "Erich E. Hoover", "wined3d: Silence repeated resource_check_usage FIXME.", 2 },';
+		printf '%s\n' '+    { "Christian Costa", "wined3d: Print FIXME only once in surface_cpu_blt.", 1 },';
+		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence repeated wined3d_swapchain_present FIXME.", 1 },';
+		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence extremely noisy FIXME in wined3d_texture_add_dirty_region.", 1 },';
+		printf '%s\n' '+    { "Christian Costa", "wined3d: Display FIXME only once when blen op is 0.", 1 },';
+		printf '%s\n' '+    { "Christian Costa", "wined3d: Silence noisy fixme Unrecognized stencil op 0.", 1 },';
+	) >> "$patchlist"
+fi
+
+# Patchset wined3d-Blend_Factor
+# |
+# | This patchset has the following (direct or indirect) dependencies:
+# |   *	wined3d-Silence_FIXMEs
+# |
+# | Modified files:
+# |   *	dlls/wined3d/state.c, include/wine/wined3d.h
+# |
+if test "$enable_wined3d_Blend_Factor" -eq 1; then
+	patch_apply wined3d-Blend_Factor/0001-wined3d-Add-more-blend-modes.patch
+	(
+		printf '%s\n' '+    { "Michael Müller", "wined3d: Add more blend modes.", 1 },';
+	) >> "$patchlist"
+fi
+
 # Patchset wined3d-QUERY_Stubs
 # |
 # | This patchset fixes the following Wine bugs:
@@ -8476,35 +8531,6 @@ if test "$enable_wined3d_Revert_Pixel_Center_Offset" -eq 1; then
 	) >> "$patchlist"
 fi
 
-# Patchset wined3d-Silence_FIXMEs
-# |
-# | This patchset fixes the following Wine bugs:
-# |   *	[#42140] Silence noisy FIXME in gl_stencil_op
-# |
-# | Modified files:
-# |   *	dlls/wined3d/resource.c, dlls/wined3d/state.c, dlls/wined3d/surface.c, dlls/wined3d/swapchain.c, dlls/wined3d/texture.c
-# |
-if test "$enable_wined3d_Silence_FIXMEs" -eq 1; then
-	patch_apply wined3d-Silence_FIXMEs/0001-wined3d-Silence-repeated-Unhandled-blend-factor-0-me.patch
-	patch_apply wined3d-Silence_FIXMEs/0002-wined3d-Display-FIXME-for-cmp-function-0-only-once.patch
-	patch_apply wined3d-Silence_FIXMEs/0003-wined3d-Silence-repeated-resource_check_usage-FIXME.patch
-	patch_apply wined3d-Silence_FIXMEs/0004-wined3d-Print-FIXME-only-once-in-surface_cpu_blt.patch
-	patch_apply wined3d-Silence_FIXMEs/0005-wined3d-Silence-repeated-wined3d_swapchain_present-F.patch
-	patch_apply wined3d-Silence_FIXMEs/0006-wined3d-Silence-extremely-noisy-FIXME-in-wined3d_tex.patch
-	patch_apply wined3d-Silence_FIXMEs/0007-wined3d-Display-FIXME-only-once-when-blen-op-is-0.patch
-	patch_apply wined3d-Silence_FIXMEs/0008-wined3d-Silence-noisy-fixme-Unrecognized-stencil-op-.patch
-	(
-		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence repeated '\''Unhandled blend factor 0'\'' messages.", 1 },';
-		printf '%s\n' '+    { "Christian Costa", "wined3d: Display FIXME for cmp function 0 only once.", 1 },';
-		printf '%s\n' '+    { "Erich E. Hoover", "wined3d: Silence repeated resource_check_usage FIXME.", 2 },';
-		printf '%s\n' '+    { "Christian Costa", "wined3d: Print FIXME only once in surface_cpu_blt.", 1 },';
-		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence repeated wined3d_swapchain_present FIXME.", 1 },';
-		printf '%s\n' '+    { "Sebastian Lackner", "wined3d: Silence extremely noisy FIXME in wined3d_texture_add_dirty_region.", 1 },';
-		printf '%s\n' '+    { "Christian Costa", "wined3d: Display FIXME only once when blen op is 0.", 1 },';
-		printf '%s\n' '+    { "Christian Costa", "wined3d: Silence noisy fixme Unrecognized stencil op 0.", 1 },';
-	) >> "$patchlist"
-fi
-
 # Patchset wined3d-CSMT_Helper
 # |
 # | This patchset has the following (direct or indirect) dependencies:
diff --git a/patches/wined3d-Blend_Factor/0001-wined3d-Add-more-blend-modes.patch b/patches/wined3d-Blend_Factor/0001-wined3d-Add-more-blend-modes.patch
new file mode 100644
index 00000000..c03cd2b4
--- /dev/null
+++ b/patches/wined3d-Blend_Factor/0001-wined3d-Add-more-blend-modes.patch
@@ -0,0 +1,47 @@
+From 835b3f4dbfff6eb52e605933387200b488ded25a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
+Date: Sun, 22 Jan 2017 15:00:38 +0100
+Subject: wined3d: Add more blend modes.
+
+---
+ dlls/wined3d/state.c   | 8 ++++++++
+ include/wine/wined3d.h | 4 ++++
+ 2 files changed, 12 insertions(+)
+
+diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
+index 5952c6cc610..1a8c0431511 100644
+--- a/dlls/wined3d/state.c
++++ b/dlls/wined3d/state.c
+@@ -412,6 +412,14 @@ static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_fo
+             return GL_CONSTANT_COLOR_EXT;
+         case WINED3D_BLEND_INVBLENDFACTOR:
+             return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
++        case WINED3D_BLEND_SRC1COLOR:
++            return GL_SRC1_COLOR;
++        case WINED3D_BLEND_INVSRC1COLOR:
++            return GL_ONE_MINUS_SRC1_COLOR;
++        case WINED3D_BLEND_SRC1ALPHA:
++            return GL_SRC1_ALPHA;
++        case WINED3D_BLEND_INVSRC1ALPHA:
++            return GL_ONE_MINUS_SRC1_ALPHA;
+         default:
+         {
+             static int once;
+diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
+index dc333448772..ffad17fa6e8 100644
+--- a/include/wine/wined3d.h
++++ b/include/wine/wined3d.h
+@@ -400,6 +400,10 @@ enum wined3d_blend
+     WINED3D_BLEND_BOTHINVSRCALPHA           = 13,
+     WINED3D_BLEND_BLENDFACTOR               = 14,
+     WINED3D_BLEND_INVBLENDFACTOR            = 15,
++    WINED3D_BLEND_SRC1COLOR                 = 16,
++    WINED3D_BLEND_INVSRC1COLOR              = 17,
++    WINED3D_BLEND_SRC1ALPHA                 = 18,
++    WINED3D_BLEND_INVSRC1ALPHA              = 19,
+ };
+ 
+ enum wined3d_blend_op
+-- 
+2.11.0
+
diff --git a/patches/wined3d-Blend_Factor/definition b/patches/wined3d-Blend_Factor/definition
new file mode 100644
index 00000000..5770e7e3
--- /dev/null
+++ b/patches/wined3d-Blend_Factor/definition
@@ -0,0 +1,2 @@
+Fixes: Implement some more wined3d blend modes
+Depends: wined3d-Silence_FIXMEs
diff --git a/patches/wined3d-CSMT_Main/9999-IfDefined.patch b/patches/wined3d-CSMT_Main/9999-IfDefined.patch
index d4e0af61..bd7518b1 100644
--- a/patches/wined3d-CSMT_Main/9999-IfDefined.patch
+++ b/patches/wined3d-CSMT_Main/9999-IfDefined.patch
@@ -6184,7 +6184,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      {
          TRACE("No Z buffer - disabling depth test\n");
          zenable = WINED3D_ZB_FALSE;
-@@ -466,11 +470,19 @@ static void state_blend(struct wined3d_context *context, const struct wined3d_st
+@@ -474,11 +478,19 @@ static void state_blend(struct wined3d_context *context, const struct wined3d_st
          checkGLcall("glDisable(GL_LINE_SMOOTH)");
      }
  
@@ -6204,7 +6204,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
  
          /* Disable blending in all cases even without pixelshaders.
           * With blending on we could face a big performance penalty.
-@@ -861,7 +873,11 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
+@@ -869,7 +881,11 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
      GLint depthFail_back;
  
      /* No stencil test without a stencil buffer. */
@@ -6216,7 +6216,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      {
          gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
          checkGLcall("glDisable GL_STENCIL_TEST");
-@@ -957,7 +973,11 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
+@@ -965,7 +981,11 @@ static void state_stencil(struct wined3d_context *context, const struct wined3d_
  
  static void state_stencilwrite2s(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
  {
@@ -6228,7 +6228,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      const struct wined3d_gl_info *gl_info = context->gl_info;
  
      GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
-@@ -971,7 +991,11 @@ static void state_stencilwrite2s(struct wined3d_context *context, const struct w
+@@ -979,7 +999,11 @@ static void state_stencilwrite2s(struct wined3d_context *context, const struct w
  
  static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
  {
@@ -6240,7 +6240,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      const struct wined3d_gl_info *gl_info = context->gl_info;
  
      gl_info->gl_ops.gl.p_glStencilMask(mask);
-@@ -1709,7 +1733,11 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
+@@ -1717,7 +1741,11 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
      if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
              || state->render_states[WINED3D_RS_DEPTHBIAS])
      {
@@ -6252,7 +6252,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
          float scale;
  
          union
-@@ -3642,7 +3670,11 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
+@@ -3650,7 +3678,11 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
              }
              else
              {
@@ -6264,7 +6264,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
                  {
                      ERR("Failed to create sampler.\n");
                      sampler = NULL;
-@@ -4623,8 +4655,13 @@ static void vertexdeclaration(struct wined3d_context *context, const struct wine
+@@ -4631,8 +4663,13 @@ static void vertexdeclaration(struct wined3d_context *context, const struct wine
  
  static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
  {
@@ -6278,7 +6278,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      const struct wined3d_gl_info *gl_info = context->gl_info;
      struct wined3d_viewport vp = state->viewport;
      unsigned int width, height;
-@@ -4636,7 +4673,11 @@ static void viewport_miscpart(struct wined3d_context *context, const struct wine
+@@ -4644,7 +4681,11 @@ static void viewport_miscpart(struct wined3d_context *context, const struct wine
          if (vp.height > target->height)
              vp.height = target->height;
  
@@ -6290,7 +6290,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      }
      else if (depth_stencil)
      {
-@@ -4663,8 +4704,13 @@ static void viewport_miscpart(struct wined3d_context *context, const struct wine
+@@ -4671,8 +4712,13 @@ static void viewport_miscpart(struct wined3d_context *context, const struct wine
  static void viewport_miscpart_cc(struct wined3d_context *context,
          const struct wined3d_state *state, DWORD state_id)
  {
@@ -6304,7 +6304,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      float pixel_center_offset = context->d3d_info->wined3d_creation_flags
              & WINED3D_PIXEL_CENTER_INTEGER ? 0.5f : 0.0f;
      const struct wined3d_gl_info *gl_info = context->gl_info;
-@@ -4678,7 +4724,11 @@ static void viewport_miscpart_cc(struct wined3d_context *context,
+@@ -4686,7 +4732,11 @@ static void viewport_miscpart_cc(struct wined3d_context *context,
          if (vp.height > target->height)
              vp.height = target->height;
  
@@ -6316,7 +6316,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
      }
      else if (depth_stencil)
      {
-@@ -4859,13 +4909,21 @@ static void scissorrect(struct wined3d_context *context, const struct wined3d_st
+@@ -4867,13 +4917,21 @@ static void scissorrect(struct wined3d_context *context, const struct wined3d_st
      }
      else
      {
@@ -6338,7 +6338,7 @@ diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
              gl_info->gl_ops.gl.p_glScissor(r->left, height - r->bottom, r->right - r->left, r->bottom - r->top);
          }
          else
-@@ -4943,7 +5001,11 @@ void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state
+@@ -4951,7 +5009,11 @@ void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state
  
      TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
  
@@ -9540,7 +9540,7 @@ diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
 diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
 --- a/include/wine/wined3d.h
 +++ b/include/wine/wined3d.h
-@@ -886,6 +886,7 @@ enum wined3d_format_support
+@@ -890,6 +890,7 @@ enum wined3d_format_support
  
  #define WINED3DDP_MAXTEXCOORD                                   8
  
@@ -9548,7 +9548,7 @@ diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
  #define WINED3D_BIND_VERTEX_BUFFER                              0x00000001
  #define WINED3D_BIND_INDEX_BUFFER                               0x00000002
  #define WINED3D_BIND_CONSTANT_BUFFER                            0x00000004
-@@ -895,6 +896,7 @@ enum wined3d_format_support
+@@ -899,6 +900,7 @@ enum wined3d_format_support
  #define WINED3D_BIND_DEPTH_STENCIL                              0x00000040
  #define WINED3D_BIND_UNORDERED_ACCESS                           0x00000080
  
diff --git a/staging/VERSION b/staging/VERSION
index af098b80..cc8cdf92 100644
--- a/staging/VERSION
+++ b/staging/VERSION
@@ -1 +1 @@
-Wine Staging 2.0-rc6
+Wine Staging 2.0-rc7 (unreleased)