[Cogl] [PATCH] Use GL_ARB_sampler_objects

Robert Bragg robert at sixbynine.org
Thu Apr 5 02:43:38 PDT 2012


>  void
> @@ -1688,31 +1674,14 @@ _cogl_pipeline_layer_hash_texture_data_state (CoglPipelineLayer *authority,
>  }
>
>  void
> -_cogl_pipeline_layer_hash_filters_state (CoglPipelineLayer *authority,
> +_cogl_pipeline_layer_hash_sampler_state (CoglPipelineLayer *authority,
>                                          CoglPipelineLayer **authorities,
>                                          CoglPipelineHashState *state)
>  {
> -  unsigned int hash = state->hash;
> -  hash = _cogl_util_one_at_a_time_hash (hash, &authority->mag_filter,
> -                                        sizeof (authority->mag_filter));
> -  hash = _cogl_util_one_at_a_time_hash (hash, &authority->min_filter,
> -                                        sizeof (authority->min_filter));
> -  state->hash = hash;
> -}
> -
> -void
> -_cogl_pipeline_layer_hash_wrap_modes_state (CoglPipelineLayer *authority,
> -                                            CoglPipelineLayer **authorities,
> -                                            CoglPipelineHashState *state)
> -{
> -  unsigned int hash = state->hash;
> -  hash = _cogl_util_one_at_a_time_hash (hash, &authority->wrap_mode_s,
> -                                        sizeof (authority->wrap_mode_s));
> -  hash = _cogl_util_one_at_a_time_hash (hash, &authority->wrap_mode_t,
> -                                        sizeof (authority->wrap_mode_t));
> -  hash = _cogl_util_one_at_a_time_hash (hash, &authority->wrap_mode_p,
> -                                        sizeof (authority->wrap_mode_p));
> -  state->hash = hash;
> +  state->hash =
> +    _cogl_util_one_at_a_time_hash (state->hash,
> +                                   &authority->sampler_cache_entry,
> +                                   sizeof (authority->sampler_cache_entry));
>  }
>
>  void

> +static unsigned int
> +hash_wrap_mode_gl (unsigned int hash,
> +                   CoglSamplerCacheWrapMode wrap_mode)
> +{
> +  /* We want to hash the actual GLenum that will be used so that if
> +     two different wrap_modes actually use the same GL state we'll
> +     still use the same sampler object */
> +  GLenum real_wrap_mode = get_real_wrap_mode (wrap_mode);
> +
> +  return _cogl_util_one_at_a_time_hash (hash,
> +                                        &real_wrap_mode,
> +                                        sizeof (real_wrap_mode));
> +}
> +
> +static unsigned int
> +hash_sampler_state_gl (const void *key)
> +{
> +  const CoglSamplerCacheEntry *entry = key;
> +  unsigned int hash = 0;
> +
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->mag_filter,
> +                                        sizeof (entry->mag_filter));
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->min_filter,
> +                                        sizeof (entry->min_filter));
> +  hash = hash_wrap_mode_gl (hash, entry->wrap_mode_s);
> +  hash = hash_wrap_mode_gl (hash, entry->wrap_mode_t);
> +  hash = hash_wrap_mode_gl (hash, entry->wrap_mode_p);
> +
> +  return hash;
> +}
> +
> +static gboolean
> +sampler_state_equal_cogl (const void *value0,
> +                          const void *value1)
> +{
> +  const CoglSamplerCacheEntry *state0 = value0;
> +  const CoglSamplerCacheEntry *state1 = value1;
> +
> +  return (state0->mag_filter == state1->mag_filter &&
> +          state0->min_filter == state1->min_filter &&
> +          state0->wrap_mode_s == state1->wrap_mode_s &&
> +          state0->wrap_mode_t == state1->wrap_mode_t &&
> +          state0->wrap_mode_p == state1->wrap_mode_p);
> +}
> +
> +static unsigned int
> +hash_sampler_state_cogl (const void *key)
> +{
> +  const CoglSamplerCacheEntry *entry = key;
> +  unsigned int hash = 0;
> +
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->mag_filter,
> +                                        sizeof (entry->mag_filter));
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->min_filter,
> +                                        sizeof (entry->min_filter));
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->wrap_mode_s,
> +                                        sizeof (entry->wrap_mode_s));
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->wrap_mode_t,
> +                                        sizeof (entry->wrap_mode_t));
> +  hash = _cogl_util_one_at_a_time_hash (hash, &entry->wrap_mode_p,
> +                                        sizeof (entry->wrap_mode_p));
> +
> +  return hash;
> +}

When using _cogl_util_one_at_a_time_hash it's intended that you should
also call _cogl_util_one_at_a_time_mix() just before returning the
final hash.

Apart from that this patch looks like a nice patch to land to me.

Reviewed-by: Robert Bragg <robert at linux.intel.com>

kind regards,
- Robert


More information about the Cogl mailing list