Guest User

Untitled

a guest
May 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. From 6ea4c67ba24194b4411897af07bf8a9584e26edc Mon Sep 17 00:00:00 2001
  2. From: Neil Roberts <neil@linux.intel.com>
  3. Date: Thu, 13 May 2010 13:17:19 +0100
  4. Subject: [PATCH] cogl-material: Enable blending if a transparent blend constant is used
  5.  
  6. If the blend constant is used by one of the blending factors and the
  7. constant is not fully opaque then blending will now be enabled.
  8. ---
  9. clutter/cogl/cogl/cogl-material.c | 55 +++++++++++++++++++++++++-----------
  10. 1 files changed, 38 insertions(+), 17 deletions(-)
  11.  
  12. diff --git a/clutter/cogl/cogl/cogl-material.c b/clutter/cogl/cogl/cogl-material.c
  13. index 5c6b93b..0bd071f 100644
  14. --- a/clutter/cogl/cogl/cogl-material.c
  15. +++ b/clutter/cogl/cogl/cogl-material.c
  16. @@ -166,6 +166,28 @@ _cogl_material_free (CoglMaterial *material)
  17. g_slice_free (CoglMaterial, material);
  18. }
  19.  
  20. +#ifndef HAVE_COGL_GLES
  21. +
  22. +static gboolean
  23. +blend_factor_uses_constant (GLenum blend_factor)
  24. +{
  25. + return (blend_factor == GL_CONSTANT_COLOR ||
  26. + blend_factor == GL_ONE_MINUS_CONSTANT_COLOR ||
  27. + blend_factor == GL_CONSTANT_ALPHA ||
  28. + blend_factor == GL_ONE_MINUS_CONSTANT_ALPHA);
  29. +}
  30. +
  31. +static gboolean
  32. +_cogl_material_any_blend_factor_uses_constant (CoglMaterial *material)
  33. +{
  34. + return (blend_factor_uses_constant (material->blend_src_factor_rgb) ||
  35. + blend_factor_uses_constant (material->blend_src_factor_alpha) ||
  36. + blend_factor_uses_constant (material->blend_dst_factor_rgb) ||
  37. + blend_factor_uses_constant (material->blend_dst_factor_alpha));
  38. +}
  39. +
  40. +#endif /* HAVE_COGL_GLES */
  41. +
  42. static gboolean
  43. _cogl_material_needs_blending_enabled (CoglMaterial *material,
  44. GLubyte *override_color)
  45. @@ -188,6 +210,12 @@ _cogl_material_needs_blending_enabled (CoglMaterial *material,
  46. material->emission[3] != 1.0f)
  47. return TRUE;
  48.  
  49. +#ifndef HAVE_COGL_GLES
  50. + if (_cogl_material_any_blend_factor_uses_constant (material) &&
  51. + material->blend_constant[3] != 1.0f)
  52. + return TRUE;
  53. +#endif
  54. +
  55. for (tmp = material->layers; tmp != NULL; tmp = tmp->next)
  56. {
  57. CoglMaterialLayer *layer = tmp->data;
  58. @@ -707,6 +735,10 @@ cogl_material_set_blend (CoglHandle handle,
  59.  
  60. material->flags &= ~COGL_MATERIAL_FLAG_DEFAULT_BLEND;
  61.  
  62. + /* If the blend mode is changed to use a the blend constant for one
  63. + of the factors then it may now need blending enabled */
  64. + handle_automatic_blend_enable (material);
  65. +
  66. return TRUE;
  67. }
  68.  
  69. @@ -732,6 +764,11 @@ cogl_material_set_blend_constant (CoglHandle handle,
  70. constant[3] = cogl_color_get_alpha_float (constant_color);
  71.  
  72. material->flags &= ~COGL_MATERIAL_FLAG_DEFAULT_BLEND;
  73. +
  74. + /* If the constant is not fully opaque then the material may now
  75. + need blending enabled */
  76. + handle_automatic_blend_enable (material);
  77. +
  78. #endif
  79. }
  80.  
  81. @@ -1636,19 +1673,6 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
  82. }
  83. }
  84.  
  85. -#ifndef HAVE_COGL_GLES
  86. -
  87. -static gboolean
  88. -blend_factor_uses_constant (GLenum blend_factor)
  89. -{
  90. - return (blend_factor == GL_CONSTANT_COLOR ||
  91. - blend_factor == GL_ONE_MINUS_CONSTANT_COLOR ||
  92. - blend_factor == GL_CONSTANT_ALPHA ||
  93. - blend_factor == GL_ONE_MINUS_CONSTANT_ALPHA);
  94. -}
  95. -
  96. -#endif
  97. -
  98. static void
  99. _cogl_material_flush_base_gl_state (CoglMaterial *material,
  100. gboolean skip_gl_color)
  101. @@ -1717,10 +1741,7 @@ _cogl_material_flush_base_gl_state (CoglMaterial *material,
  102. else
  103. GE (glBlendEquation (material->blend_equation_rgb));
  104.  
  105. - if (blend_factor_uses_constant (material->blend_src_factor_rgb) ||
  106. - blend_factor_uses_constant (material->blend_src_factor_alpha) ||
  107. - blend_factor_uses_constant (material->blend_dst_factor_rgb) ||
  108. - blend_factor_uses_constant (material->blend_dst_factor_alpha))
  109. + if (_cogl_material_any_blend_factor_uses_constant (material))
  110. GE (glBlendColor (material->blend_constant[0],
  111. material->blend_constant[1],
  112. material->blend_constant[2],
  113. --
  114. 1.6.5.rc1.46.g4d818
Add Comment
Please, Sign In to add comment