enum return_code
WRATHAttributeStore::
fragmented_allocate_attribute_data(int number_elements,
                                   std::vector< range_type<int> > &out_allocations)
{

    WRATHAutoLockMutex(m_implicit_store_mutex);

    enum return_code R;
    int biggest_end(0), start_div_at(out_allocations.size());

    R=m_vertex_buffer->fragmented_allocate(attribute_size()*number_elements, out_allocations);

    if(R==routine_success)
    {
        for(int i=start_div_at, end_i=out_allocations.size(); i<end_i; ++i)
        {
            WRATHassert(out_allocations[i].m_begin%attribute_size()==0);
            WRATHassert(out_allocations[i].m_end%attribute_size()==0);

            out_allocations[i].m_begin/=attribute_size();
            out_allocations[i].m_end/=attribute_size();
            biggest_end=std::max(out_allocations[i].m_end, biggest_end);
        }

        int required_implicit_attr_size(m_implicit_attribute_size*biggest_end);
        resize_implicit_stores(required_implicit_attr_size);
    }

    return R;
}
void
WRATHAttributeStore::
deallocate_attribute_data(int begin_element, int end_element)
{
    begin_element*=attribute_size();
    end_element*=attribute_size();

    m_vertex_buffer->deallocate(begin_element, end_element);
}
Beispiel #3
0
attribute attribute_find ( relation rel, char *name) {
/* attribute_find
 * Locates the given attribute, and returns an attribute structure
 */
	attribute catt,ratt;
	tuple ctuple;
	word anum;

	/* Get the first attribute */
	/* catt=attribute_findfirst(rel,&attribute_file); */
	catt=relation_attribute_readfirst(rel,&ctuple,&anum);

	/* Whilst the attribute is valid, and the attribute does
	 * not match the search criteria 
	 */
	while ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)!=0) ) {

		/* Locate the next field */
		catt=relation_attribute_readnext(rel,&ctuple,catt,&anum);
	}

	/* Check to see if we actually found anything */
	if ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)==0) ) {
	
		/* We're about to destroy the tuple, which will destroy the attribute
		 * we just found. Make a copy quick!
		 */
		/* Create a ptr to an attribute structure */
		ratt=(attribute_struct *) malloc(sizeof(attribute_struct));
	
		/* Check that the ptr was allocated. */
		check_assign(ratt,"attributes.attribute_find(cpy)");

		strcpy(attribute_name(ratt),attribute_name(catt));
		attribute_type(ratt)=attribute_type(catt);
		attribute_size(ratt)=attribute_size(catt);
		attribute_no(ratt)=attribute_no(catt);
		
		close_tuple(&ctuple,TUPLE_DISPOSE);

		/* Return the ptr */
		return(ratt);
	} else {
	
		/* Close the tuple */
		close_tuple(&ctuple,TUPLE_DISPOSE);

		/* Return nothing */	
		return(NULL);
	}
}
WRATHAttributeStore::
~WRATHAttributeStore()
{
    deallocate_attribute_data(0,1);

    if(attributes_allocated()!=0)
    {
        WRATHwarning("[" << this << "]"
                     << ":" << m_vertex_buffer
                     << ": Warning: not all attributes de-allocated! "
                     << attributes_allocated()  << " attributes remain"
                     << "{ attribute size=" << attribute_size()
                     << " }");
    }

    WRATHPhasedDelete(m_vertex_buffer);

    WRATHLockMutex(m_allocator_ptr_mutex);
    if(m_allocator!=NULL)
    {
        m_allocator->unregister(this);
    }

    for(std::map<unsigned int, per_implicit_store*>::iterator
            iter=m_implicit_attribute_data.begin(),
            end=m_implicit_attribute_data.end();
            iter!=end; ++iter)
    {
        WRATHPhasedDelete(iter->second);
    }

    WRATHUnlockMutex(m_allocator_ptr_mutex);
}
enum return_code
WRATHAttributeStore::
proxy_fragmented_allocate_attribute(int number_elements) const
{
    return (number_elements<=0)?
    routine_success:
    m_vertex_buffer->proxy_fragmented_allocate(number_elements*attribute_size());
}
int
WRATHAttributeStore::
allocate_attribute_data(int number_elements)
{
    WRATHAutoLockMutex(m_implicit_store_mutex);

    int raw_value;
    raw_value=m_vertex_buffer->allocate(number_elements*attribute_size());

    if(raw_value==-1)
    {
        return raw_value;
    }

    WRATHassert(raw_value%attribute_size()==0);
    raw_value/=attribute_size();

    int required_implicit_attr_size(m_implicit_attribute_size*(number_elements+raw_value));
    resize_implicit_stores(required_implicit_attr_size);

    return raw_value;
}
Beispiel #7
0
void attribute_print(attribute att) {
/* attribute_print
 * Print out the information contained in the specified
 * attribute
 */
	char fmt[FORMAT_SIZE];

	fmt_build(fmt,att);

	/* Check that the ptr is assigned! */
	if (att!=NULL) {
		switch (attribute_type(att)) {
			case DT_STRING:
				leap_printf(DTS_STRING);
				leap_printf("      ");
				break;
			case DT_NUMBER:
				leap_printf(DTS_NUMBER);
				leap_printf("     ");
				break;
			case DT_BOOLEAN:
				leap_printf(DTS_BOOLEAN);
				leap_printf("     ");
				break;
			default:
				leap_printf(DTS_UNSUPPORTED);
				leap_printf(" ");
		}
		if (attribute_size(att)==0) leap_printf("-");
		else leap_printf("%d",attribute_size(att));

		if (attribute_size(att)<9) leap_printf("   ");
		else if (attribute_size(att)<99) leap_printf("  ");
		else leap_printf(" ");

		leap_printf("%-25.25s \n",attribute_name(att));
	}
}
int
WRATHAttributeStore::
attributes_allocated(void) const
{
    return m_vertex_buffer->bytes_allocated()/attribute_size();
}
int
WRATHAttributeStore::
max_fragmented_allocate_possible(void) const
{
    return m_vertex_buffer->max_fragmented_allocate_possible()/attribute_size();
}
//////////////////////////////////////
// WRATHAttributeStore methods
WRATHAttributeStore::
WRATHAttributeStore(const WRATHAttributeStoreKey &pkey,
                    WRATHAttributeStoreAllocator *allocator,
                    bool allocate_implicit_attribute_data):
    m_key(pkey),
    m_value_at_index0(allocator->m_value_at_index0),
    m_implicit_attribute_format(allocator->m_implicit_attribute_format),
    m_attribute_format_location(m_key.m_attribute_format_location),
    m_index_bits(m_key.m_index_bit_count),
    m_buffer_object_hint(m_key.m_buffer_object_hint),
    m_implicit_attribute_size(m_value_at_index0.size()),
    m_allocator(allocator),
    m_req_implicit_attribute_size(m_implicit_attribute_size)
{
    WRATHassert(m_key.valid());

    WRATHAutoLockMutex(m_allocator_ptr_mutex);

    int bo_end_byte;

    switch(m_index_bits)
    {
    case WRATHAttributeStoreKey::index_8bits:
        m_index_type=GL_UNSIGNED_BYTE;
        m_index_type_size=1;
        bo_end_byte=256*attribute_size();
        break;

    default:
        WRATHassert(0);
    //fall through on release builds..
    case WRATHAttributeStoreKey::index_16bits:
        m_index_type=GL_UNSIGNED_SHORT;
        m_index_type_size=2;
        bo_end_byte=65536*attribute_size();
        break;

    case WRATHAttributeStoreKey::index_32bits:
        m_index_type=GL_UNSIGNED_INT;
        m_index_type_size=4;
        bo_end_byte=std::numeric_limits<int>::max();
        break;
    }

    m_vertex_buffer=WRATHNew WRATHBufferAllocator(m_allocator->triple_buffer_enabler(),
                    m_buffer_object_hint,
                    bo_end_byte);



    for(m_number_non_implicit_attributes=0;
            m_number_non_implicit_attributes < WRATHDrawCallSpec::attribute_count
            and m_attribute_format_location[m_number_non_implicit_attributes].valid();
            ++m_number_non_implicit_attributes)
    {}

    for(int K=0, endK=m_implicit_attribute_format.size(), I=m_number_non_implicit_attributes;
            K<endK and I<WRATHDrawCallSpec::attribute_count; ++K, ++I)
    {
        m_attribute_format_location[I]=m_implicit_attribute_format[K];
    }

    WRATHassert(proxy_attribute_allocate(1)==routine_success);

    if(allocate_implicit_attribute_data)
    {
        add_implicit_store(0);
    }

    unsigned int R;

    R=allocate_attribute_data(1);
    WRATHassert(R==0);
    WRATHunused(R);


}