Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. From f6ca7f0e4293481f6cbe3334bda53a5e2fd48d79 Mon Sep 17 00:00:00 2001
  2. From: Robert Bragg <robert@linux.intel.com>
  3. Date: Mon, 1 Nov 2010 20:27:32 +0000
  4. Subject: [PATCH] cogl: add separate material for blended source_colors
  5.  
  6. When using cogl_set_source_color4ub there is a notable difference
  7. between colors that require blending and those that dont. When trying to
  8. modify the color of pipeline referenced by the journal we don't force a
  9. flush of the journal unless the color change will also change the
  10. blending state. By using two separate pipeline objects for handing
  11. opaque or transparent colors we can avoid ever flushing the journal when
  12. repeatedly using cogl_set_source_color and jumping between opaque and
  13. transparent colors.
  14. ---
  15. clutter/cogl/cogl/cogl-context.c | 13 ++++++++-----
  16. clutter/cogl/cogl/cogl-context.h | 5 +++--
  17. clutter/cogl/cogl/cogl.c | 19 ++++++++++++++-----
  18. 3 files changed, 25 insertions(+), 12 deletions(-)
  19.  
  20. diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c
  21. index 7395b76..1e762db 100644
  22. --- a/clutter/cogl/cogl/cogl-context.c
  23. +++ b/clutter/cogl/cogl/cogl-context.c
  24. @@ -129,7 +129,8 @@ cogl_create_context (void)
  25.  
  26. _context->legacy_fog_state.enabled = FALSE;
  27.  
  28. - _context->simple_pipeline = cogl_pipeline_new ();
  29. + _context->opaque_color_pipeline = cogl_pipeline_new ();
  30. + _context->blended_color_pipeline = cogl_pipeline_new ();
  31. _context->texture_pipeline = cogl_pipeline_new ();
  32. _context->arbfp_source_buffer = g_string_new ("");
  33. _context->source_stack = NULL;
  34. @@ -235,8 +236,8 @@ cogl_create_context (void)
  35. 0, /* auto calc row stride */
  36. default_texture_data);
  37.  
  38. - cogl_push_source (_context->simple_pipeline);
  39. - _cogl_pipeline_flush_gl_state (_context->simple_pipeline, FALSE);
  40. + cogl_push_source (_context->opaque_color_pipeline);
  41. + _cogl_pipeline_flush_gl_state (_context->opaque_color_pipeline, FALSE);
  42. _cogl_enable (enable_flags);
  43. _cogl_flush_face_winding ();
  44.  
  45. @@ -275,8 +276,10 @@ _cogl_destroy_context (void)
  46. if (_context->default_gl_texture_rect_tex)
  47. cogl_handle_unref (_context->default_gl_texture_rect_tex);
  48.  
  49. - if (_context->simple_pipeline)
  50. - cogl_handle_unref (_context->simple_pipeline);
  51. + if (_context->opaque_color_pipeline)
  52. + cogl_handle_unref (_context->opaque_color_pipeline);
  53. + if (_context->blended_color_pipeline)
  54. + cogl_handle_unref (_context->blended_color_pipeline);
  55. if (_context->texture_pipeline)
  56. cogl_handle_unref (_context->texture_pipeline);
  57.  
  58. diff --git a/clutter/cogl/cogl/cogl-context.h b/clutter/cogl/cogl/cogl-context.h
  59. index 96157cb..fd8db15 100644
  60. --- a/clutter/cogl/cogl/cogl-context.h
  61. +++ b/clutter/cogl/cogl/cogl-context.h
  62. @@ -82,8 +82,9 @@ typedef struct
  63.  
  64. CoglPipelineFogState legacy_fog_state;
  65.  
  66. - /* Materials */
  67. - CoglPipeline *simple_pipeline; /* used for set_source_color */
  68. + /* Pipelines */
  69. + CoglPipeline *opaque_color_pipeline; /* used for set_source_color */
  70. + CoglPipeline *blended_color_pipeline; /* used for set_source_color */
  71. CoglPipeline *texture_pipeline; /* used for set_source_texture */
  72. GString *arbfp_source_buffer;
  73. GList *source_stack;
  74. diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c
  75. index af3a3d5..8271c68 100644
  76. --- a/clutter/cogl/cogl/cogl.c
  77. +++ b/clutter/cogl/cogl/cogl.c
  78. @@ -369,15 +369,24 @@ _cogl_flush_face_winding (void)
  79. void
  80. cogl_set_source_color (const CoglColor *color)
  81. {
  82. - CoglColor premultiplied;
  83. + CoglPipeline *pipeline;
  84.  
  85. _COGL_GET_CONTEXT (ctx, NO_RETVAL);
  86.  
  87. - premultiplied = *color;
  88. - cogl_color_premultiply (&premultiplied);
  89. - cogl_pipeline_set_color (ctx->simple_pipeline, &premultiplied);
  90. + if (cogl_color_get_alpha_byte (color) == 0xff)
  91. + {
  92. + cogl_pipeline_set_color (ctx->opaque_color_pipeline, color);
  93. + pipeline = ctx->opaque_color_pipeline;
  94. + }
  95. + else
  96. + {
  97. + CoglColor premultiplied = *color;
  98. + cogl_color_premultiply (&premultiplied);
  99. + cogl_pipeline_set_color (ctx->blended_color_pipeline, &premultiplied);
  100. + pipeline = ctx->blended_color_pipeline;
  101. + }
  102.  
  103. - cogl_set_source (ctx->simple_pipeline);
  104. + cogl_set_source (pipeline);
  105. }
  106.  
  107. void
  108. --
  109. 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement