예제 #1
0
struct translate *translate_generic_create( const struct translate_key *key )
{
   struct translate_generic *tg = CALLOC_STRUCT(translate_generic);
   unsigned i;

   if (tg == NULL)
      return NULL;

   tg->translate.key = *key;
   tg->translate.release = generic_release;
   tg->translate.set_buffer = generic_set_buffer;
   tg->translate.run_elts = generic_run_elts;
   tg->translate.run = generic_run;

   for (i = 0; i < key->nr_elements; i++) {
      tg->attrib[i].type = key->element[i].type;

      tg->attrib[i].fetch = get_fetch_func(key->element[i].input_format);
      tg->attrib[i].buffer = key->element[i].input_buffer;
      tg->attrib[i].input_offset = key->element[i].input_offset;
      tg->attrib[i].instance_divisor = key->element[i].instance_divisor;

      tg->attrib[i].emit = get_emit_func(key->element[i].output_format);
      tg->attrib[i].output_offset = key->element[i].output_offset;

   }

   tg->nr_attrib = key->nr_elements;


   return &tg->translate;
}
예제 #2
0
struct translate *translate_generic_create( const struct translate_key *key )
{
   struct translate_generic *tg = CALLOC_STRUCT(translate_generic);
   unsigned i;

   if (tg == NULL)
      return NULL;

   tg->translate.key = *key;
   tg->translate.release = generic_release;
   tg->translate.set_buffer = generic_set_buffer;
   tg->translate.run_elts = generic_run_elts;
   tg->translate.run_elts16 = generic_run_elts16;
   tg->translate.run_elts8 = generic_run_elts8;
   tg->translate.run = generic_run;

   for (i = 0; i < key->nr_elements; i++) {
      const struct util_format_description *format_desc =
            util_format_description(key->element[i].input_format);

      assert(format_desc);
      assert(format_desc->fetch_rgba_float);

      tg->attrib[i].type = key->element[i].type;

      tg->attrib[i].fetch = format_desc->fetch_rgba_float;
      tg->attrib[i].buffer = key->element[i].input_buffer;
      tg->attrib[i].input_offset = key->element[i].input_offset;
      tg->attrib[i].instance_divisor = key->element[i].instance_divisor;

      tg->attrib[i].output_offset = key->element[i].output_offset;

      tg->attrib[i].copy_size = -1;
      if (tg->attrib[i].type == TRANSLATE_ELEMENT_INSTANCE_ID)
      {
            if(key->element[i].output_format == PIPE_FORMAT_R32_USCALED
                  || key->element[i].output_format == PIPE_FORMAT_R32_SSCALED)
               tg->attrib[i].copy_size = 4;
      }
      else
      {
         if(key->element[i].input_format == key->element[i].output_format
               && format_desc->block.width == 1
               && format_desc->block.height == 1
               && !(format_desc->block.bits & 7))
            tg->attrib[i].copy_size = format_desc->block.bits >> 3;
      }

      if(tg->attrib[i].copy_size < 0)
	      tg->attrib[i].emit = get_emit_func(key->element[i].output_format);
      else
	      tg->attrib[i].emit  = NULL;
   }

   tg->nr_attrib = key->nr_elements;


   return &tg->translate;
}