Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. From 076f4d76fd2f36892941d4d4474986f97be64112 Mon Sep 17 00:00:00 2001
  2. From: Robert Bragg <robert@linux.intel.com>
  3. Date: Mon, 1 Nov 2010 18:55:48 +0000
  4. Subject: [PATCH] texture_quad_multiple_primitives: rework wrap mode overrides
  5.  
  6. This reworks _cogl_texture_quad_multiple_primitives so instead of using
  7. the CoglPipelineWrapModeOverrides mechanism to force the clamp to edge
  8. repeat mode we now derive an override pipeline using cogl_pipeline_copy
  9. instead. This avoids a relatively large, unconditional, memset.
  10. ---
  11. clutter/cogl/cogl/cogl-primitives.c | 82 ++++++++++++++++++++++------------
  12. 1 files changed, 53 insertions(+), 29 deletions(-)
  13.  
  14. diff --git a/clutter/cogl/cogl/cogl-primitives.c b/clutter/cogl/cogl/cogl-primitives.c
  15. index 782df9d..6b9641a 100644
  16. --- a/clutter/cogl/cogl/cogl-primitives.c
  17. +++ b/clutter/cogl/cogl/cogl-primitives.c
  18. @@ -60,7 +60,6 @@ typedef struct _TextureSlicedQuadState
  19. float quad_len_y;
  20. gboolean flipped_x;
  21. gboolean flipped_y;
  22. - CoglPipelineWrapModeOverrides *wrap_mode_overrides;
  23. } TextureSlicedQuadState;
  24.  
  25. typedef struct _TextureSlicedPolygonState
  26. @@ -114,18 +113,55 @@ log_quad_sub_textures_cb (CoglHandle texture_handle,
  27. subtexture_coords[0], subtexture_coords[1],
  28. subtexture_coords[2], subtexture_coords[3]);
  29.  
  30. - /* FIXME: when the wrap mode becomes part of the pipeline we need to
  31. - * be able to override the wrap mode when logging a quad. */
  32. _cogl_journal_log_quad (quad_coords,
  33. state->pipeline,
  34. 1, /* one layer */
  35. 0, /* don't need to use fallbacks */
  36. gl_handle, /* replace the layer0 texture */
  37. - state->wrap_mode_overrides, /* use GL_CLAMP_TO_EDGE */
  38. + NULL, /* we never use wrap mode overrides */
  39. subtexture_coords,
  40. 4);
  41. }
  42.  
  43. +typedef struct _ValidateFirstLayerState
  44. +{
  45. + CoglPipeline *override_pipeline;
  46. +} ValidateFirstLayerState;
  47. +
  48. +static gboolean
  49. +validate_first_layer_cb (CoglPipeline *pipeline,
  50. + int layer_index,
  51. + void *user_data)
  52. +{
  53. + ValidateFirstLayerState *state = user_data;
  54. + CoglPipelineWrapMode clamp_to_edge =
  55. + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
  56. +
  57. + /* We can't use hardware repeat so we need to set clamp to edge
  58. + * otherwise it might pull in edge pixels from the other side. By
  59. + * default WRAP_MODE_AUTOMATIC becomes CLAMP_TO_EDGE so we only need
  60. + * to override if the wrap mode is repeat.
  61. + */
  62. + if (cogl_pipeline_get_layer_wrap_mode_s (pipeline, layer_index) ==
  63. + COGL_PIPELINE_WRAP_MODE_REPEAT)
  64. + {
  65. + if (!state->override_pipeline)
  66. + state->override_pipeline = cogl_pipeline_copy (pipeline);
  67. + cogl_pipeline_set_layer_wrap_mode_s (pipeline, layer_index,
  68. + clamp_to_edge);
  69. + }
  70. + if (cogl_pipeline_get_layer_wrap_mode_t (pipeline, layer_index) ==
  71. + COGL_PIPELINE_WRAP_MODE_REPEAT)
  72. + {
  73. + if (!state->override_pipeline)
  74. + state->override_pipeline = cogl_pipeline_copy (pipeline);
  75. + cogl_pipeline_set_layer_wrap_mode_t (pipeline, layer_index,
  76. + clamp_to_edge);
  77. + }
  78. +
  79. + return FALSE;
  80. +}
  81. +
  82. /* This path doesn't currently support multitexturing but is used for
  83. * CoglTextures that don't support repeating using the GPU so we need to
  84. * manually emit extra geometry to fake the repeating. This includes:
  85. @@ -152,12 +188,11 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
  86. float ty_2)
  87. {
  88. TextureSlicedQuadState state;
  89. - CoglPipelineWrapModeOverrides wrap_mode_overrides;
  90. gboolean tex_virtual_flipped_x;
  91. gboolean tex_virtual_flipped_y;
  92. gboolean quad_flipped_x;
  93. gboolean quad_flipped_y;
  94. - CoglHandle first_layer;
  95. + ValidateFirstLayerState validate_first_layer_state;
  96.  
  97. _COGL_GET_CONTEXT (ctx, NO_RETVAL);
  98.  
  99. @@ -259,30 +294,13 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
  100. position = replacement_position;
  101. }
  102.  
  103. - state.wrap_mode_overrides = NULL;
  104. - memset (&wrap_mode_overrides, 0, sizeof (wrap_mode_overrides));
  105. -
  106. - /* We can't use hardware repeat so we need to set clamp to edge
  107. - otherwise it might pull in edge pixels from the other side. By
  108. - default WRAP_MODE_AUTOMATIC becomes CLAMP_TO_EDGE so we only need
  109. - to override if the wrap mode is repeat */
  110. - first_layer = _cogl_pipeline_get_layers (pipeline)->data;
  111. - if (_cogl_pipeline_layer_get_wrap_mode_s (first_layer) ==
  112. - COGL_PIPELINE_WRAP_MODE_REPEAT)
  113. - {
  114. - state.wrap_mode_overrides = &wrap_mode_overrides;
  115. - wrap_mode_overrides.values[0].s =
  116. - COGL_PIPELINE_WRAP_MODE_OVERRIDE_CLAMP_TO_EDGE;
  117. - }
  118. - if (_cogl_pipeline_layer_get_wrap_mode_t (first_layer) ==
  119. - COGL_PIPELINE_WRAP_MODE_REPEAT)
  120. - {
  121. - state.wrap_mode_overrides = &wrap_mode_overrides;
  122. - wrap_mode_overrides.values[0].t =
  123. - COGL_PIPELINE_WRAP_MODE_OVERRIDE_CLAMP_TO_EDGE;
  124. - }
  125. + validate_first_layer_state.override_pipeline = NULL;
  126. + cogl_pipeline_foreach_layer (pipeline,
  127. + validate_first_layer_cb,
  128. + &validate_first_layer_state);
  129.  
  130. - state.pipeline = pipeline;
  131. + if (validate_first_layer_state.override_pipeline)
  132. + state.pipeline = validate_first_layer_state.override_pipeline;
  133.  
  134. /* Get together the data we need to transform the virtual texture
  135. * coordinates of each slice into quad coordinates...
  136. @@ -329,6 +347,9 @@ _cogl_texture_quad_multiple_primitives (CoglHandle tex_handle,
  137. tx_1, ty_1, tx_2, ty_2,
  138. log_quad_sub_textures_cb,
  139. &state);
  140. +
  141. + if (validate_first_layer_state.override_pipeline)
  142. + cogl_object_unref (validate_first_layer_state.override_pipeline);
  143. }
  144.  
  145. typedef struct _ValidateTexCoordsState
  146. @@ -509,6 +530,9 @@ _cogl_multitexture_quad_single_primitive (const float *position,
  147. final_tex_coords,
  148. n_layers * 4);
  149.  
  150. + if (state.override_pipeline)
  151. + cogl_object_unref (state.override_pipeline);
  152. +
  153. return TRUE;
  154. }
  155.  
  156. --
  157. 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement