Ejemplo n.º 1
0
static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *ssamp, StrandSegment *sseg, StrandVert *svert)
{
	StrandCacheEntry *entry;
	StrandPoint p;
	int *refcount;
	GHashPair pair = strand_shade_hash_pair(sseg->obi, svert);

	entry= BLI_ghash_lookup(cache->resulthash, &pair);
	refcount= BLI_ghash_lookup(cache->refcounthash, &pair);

	if (!entry) {
		/* not shaded yet, shade and insert into hash */
		p.t= (sseg->v[1] == svert)? 0.0f: 1.0f;
		strand_eval_point(sseg, &p);
		strand_shade_point(re, ssamp, sseg, svert, &p);

		entry= MEM_callocN(sizeof(StrandCacheEntry), "StrandCacheEntry");
		entry->pair = pair;
		entry->shr = ssamp->shr[0];
		BLI_ghash_insert(cache->resulthash, entry, entry);
	}
	else
		/* already shaded, just copy previous result from hash */
		ssamp->shr[0]= entry->shr;
	
	/* lower reference count and remove if not needed anymore by any samples */
	(*refcount)--;
	if (*refcount == 0) {
		BLI_ghash_remove(cache->resulthash, &pair, (GHashKeyFreeFP)MEM_freeN, NULL);
		BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL);
	}
}
Ejemplo n.º 2
0
struct ImBuf * seq_stripelem_cache_get(
	SeqRenderData context, struct Sequence * seq, 
	float cfra, seq_stripelem_ibuf_t type)
{
	seqCacheKey key;
	seqCacheEntry * e;

	if (!seq) {
		return NULL;
	}

	if (!entrypool) {
		seq_stripelem_cache_init();
	}

	key.seq = seq;
	key.context = context;
	key.cfra = cfra - seq->start;
	key.type = type;
	
	e = (seqCacheEntry*) BLI_ghash_lookup(hash, &key);

	if (e && e->ibuf) {
		IMB_refImBuf(e->ibuf);

		MEM_CacheLimiter_touch(e->c_handle);
		return e->ibuf;
	}
	return NULL;
}
Ejemplo n.º 3
0
BME_TransData *BME_assign_transdata(BME_TransData_Head *td, BME_Mesh *bm, BME_Vert *v,
		float *co, float *org, float *vec, float *loc,
		float factor, float weight, float maxfactor, float *max) {
	BME_TransData *vtd;
	int is_new = 0;

	if (v == NULL) return NULL;

	if ((vtd = BLI_ghash_lookup(td->gh, v)) == NULL && bm != NULL) {
		vtd = BLI_memarena_alloc(td->ma, sizeof(*vtd));
		BLI_ghash_insert(td->gh, v, vtd);
		td->len++;
		is_new = 1;
	}

	vtd->bm = bm;
	vtd->v = v;
	if (co != NULL) VECCOPY(vtd->co,co);
	if (org == NULL && is_new) { VECCOPY(vtd->org,v->co); } /* default */
	else if (org != NULL) VECCOPY(vtd->org,org);
	if (vec != NULL) {
		VECCOPY(vtd->vec,vec);
		normalize_v3(vtd->vec);
	}
	vtd->loc = loc;

	vtd->factor = factor;
	vtd->weight = weight;
	vtd->maxfactor = maxfactor;
	vtd->max = max;

	return vtd;
}
Ejemplo n.º 4
0
static bool ghash_insert_link(
        GHash *gh, void *key, void *val, bool use_test,
        MemArena *mem_arena)
{
	struct LinkBase *ls_base;
	LinkNode *ls;

	ls_base = BLI_ghash_lookup(gh, key);

	if (ls_base) {
		if (use_test && (BLI_linklist_index(ls_base->list, key) != -1)) {
			return false;
		}
	}
	else {
		ls_base = BLI_memarena_alloc(mem_arena, sizeof(*ls_base));
		ls_base->list     = NULL;
		ls_base->list_len = 0;
		BLI_ghash_insert(gh, key, ls_base);
	}

	ls = BLI_memarena_alloc(mem_arena, sizeof(*ls));
	ls->next = ls_base->list;
	ls->link = val;
	ls_base->list = ls;
	ls_base->list_len += 1;

	return true;
}
Ejemplo n.º 5
0
bool *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
{
	bDeformGroup *dg;
	ModifierData *md;
	bool *vgroup_validmap;
	GHash *gh;
	int i, step1 = 1;
	//int defbase_tot = BLI_countlist(&ob->defbase);

	if (ob->defbase.first == NULL) {
		return NULL;
	}

	gh = BLI_ghash_str_new("BKE_objdef_validmap_get gh");

	/* add all names to a hash table */
	for (dg = ob->defbase.first; dg; dg = dg->next) {
		BLI_ghash_insert(gh, dg->name, NULL);
	}

	BLI_assert(BLI_ghash_size(gh) == defbase_tot);

	/* now loop through the armature modifiers and identify deform bones */
	for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) {
		if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual)))
			continue;

		if (md->type == eModifierType_Armature) {
			ArmatureModifierData *amd = (ArmatureModifierData *) md;

			if (amd->object && amd->object->pose) {
				bPose *pose = amd->object->pose;
				bPoseChannel *chan;

				for (chan = pose->chanbase.first; chan; chan = chan->next) {
					if (chan->bone->flag & BONE_NO_DEFORM)
						continue;

					if (BLI_ghash_remove(gh, chan->name, NULL, NULL)) {
						BLI_ghash_insert(gh, chan->name, SET_INT_IN_POINTER(1));
					}
				}
			}
		}
	}

	vgroup_validmap = MEM_mallocN(sizeof(*vgroup_validmap) * defbase_tot, "wpaint valid map");

	/* add all names to a hash table */
	for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) {
		vgroup_validmap[i] = (BLI_ghash_lookup(gh, dg->name) != NULL);
	}

	BLI_assert(i == BLI_ghash_size(gh));

	BLI_ghash_free(gh, NULL, NULL);

	return vgroup_validmap;
}
Ejemplo n.º 6
0
Base *BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
{
  if (!view_layer->object_bases_hash) {
    view_layer_bases_hash_create(view_layer);
  }

  return BLI_ghash_lookup(view_layer->object_bases_hash, ob);
}
GPUFunction *GPU_lookup_function(const char *name)
{
	if (!FUNCTION_HASH) {
		FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh");
		gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library);
	}

	return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, (void *)name);
}
Ejemplo n.º 8
0
int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
{
	StructRNA *srna;
	PropertyRNA *prop;
	PointerRNA propptr= {{NULL}};

	srna= ptr->type;

	do {
		if(srna->cont.prophash) {
			prop= BLI_ghash_lookup(srna->cont.prophash, (void*)key);

			if(prop) {
				propptr.type= &RNA_Property;
				propptr.data= prop;

				*r_ptr= propptr;
				return TRUE;
			}
		}
		else {
			for(prop=srna->cont.properties.first; prop; prop=prop->next) {
				if(!(prop->flag & PROP_BUILTIN) && strcmp(prop->identifier, key)==0) {
					propptr.type= &RNA_Property;
					propptr.data= prop;

					*r_ptr= propptr;
					return TRUE;
				}
			}
		}
	} while((srna=srna->base));

	/* this was used pre 2.5beta0, now ID property access uses python's
	 * getitem style access
	 * - ob["foo"] rather than ob.foo */
#if 0
	if(ptr->data) {
		IDProperty *group, *idp;

		group= RNA_struct_idprops(ptr, 0);

		if(group) {
			for(idp=group->data.group.first; idp; idp=idp->next) {
				if(strcmp(idp->name, key) == 0) {
					propptr.type= &RNA_Property;
					propptr.data= idp;

					*r_ptr= propptr;
					return TRUE;
				}
			}
		}
	}
#endif
	return FALSE;
}
Ejemplo n.º 9
0
static bArgument *lookUp(struct bArgs *ba, const char *arg, int pass, int case_str)
{
	bAKey key;

	key.case_str = case_str;
	key.pass = pass;
	key.arg = arg;

	return BLI_ghash_lookup(ba->items, &key);
}
Ejemplo n.º 10
0
static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
{
	SimDebugElement *old_elem = BLI_ghash_lookup(debug_data->gh, elem);
	if (old_elem) {
		*old_elem = *elem;
		MEM_freeN(elem);
	}
	else
		BLI_ghash_insert(debug_data->gh, elem, elem);
}
Ejemplo n.º 11
0
/**
 * Return a pointer to the pose channel of the given name
 * from this pose.
 */
bPoseChannel *BKE_pose_channel_find_name(const bPose *pose, const char *name)
{
	if (ELEM(NULL, pose, name) || (name[0] == '\0'))
		return NULL;
	
	if (pose->chanhash)
		return BLI_ghash_lookup(pose->chanhash, (const void *)name);
	
	return BLI_findstring(&((const bPose *)pose)->chanbase, name, offsetof(bPoseChannel, name));
}
Ejemplo n.º 12
0
static ListBase *edge_isect_ls_ensure(GHash *isect_hash, ScanFillEdge *eed)
{
	ListBase *e_ls;
	e_ls = BLI_ghash_lookup(isect_hash, eed);
	if (e_ls == NULL) {
		e_ls = MEM_callocN(sizeof(ListBase), __func__);
		BLI_ghash_insert(isect_hash, eed, e_ls);
	}
	return e_ls;
}
Ejemplo n.º 13
0
bool IMB_moviecache_has_frame(MovieCache *cache, void *userkey)
{
	MovieCacheKey key;
	MovieCacheItem *item;

	key.cache_owner = cache;
	key.userkey = userkey;
	item = (MovieCacheItem *)BLI_ghash_lookup(cache->hash, &key);

	return item != NULL;
}
Ejemplo n.º 14
0
GPUFunction *GPU_lookup_function(const char *name)
{
	if (!FUNCTION_HASH) {
		FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh");
		gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library);
		/*FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH);
		FUNCTION_LIB = GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);*/
	}

	return (GPUFunction*)BLI_ghash_lookup(FUNCTION_HASH, (void *)name);
}
Ejemplo n.º 15
0
static TseGroup *BKE_outliner_treehash_lookup_group(GHash *th, short type, short nr, struct ID *id)
{
	TreeStoreElem tse_template;
	tse_template.type = type;
	tse_template.nr = type ? nr : 0;  // we're picky! :)
	tse_template.id = id;

	BLI_assert(th);

	return BLI_ghash_lookup(th, &tse_template);
}
Ejemplo n.º 16
0
Icon *BKE_icon_get(int icon_id)
{
	Icon *icon = NULL;

	icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id));
	
	if (!icon) {
		printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
		return NULL;
	}

	return icon;
}
Ejemplo n.º 17
0
void BKE_icon_set(int icon_id, struct Icon *icon)
{
	Icon *old_icon = NULL;

	old_icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id));

	if (old_icon) {
		printf("BKE_icon_set: Internal error, icon already set: %d\n", icon_id);
		return;
	}

	BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(icon_id), icon);
}
Ejemplo n.º 18
0
bool BKE_pose_channels_is_valid(const bPose *pose)
{
	if (pose->chanhash) {
		bPoseChannel *pchan;
		for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
			if (BLI_ghash_lookup(pose->chanhash, pchan->name) != pchan) {
				return false;
			}
		}
	}

	return true;
}
Ejemplo n.º 19
0
static unsigned int *imb_thread_cache_get_tile(ImThreadTileCache *cache, ImBuf *ibuf, int tx, int ty)
{
	ImThreadTile *ttile, lookuptile;
	ImGlobalTile *gtile, *replacetile;
	int toffs= ibuf->xtiles*ty + tx;

	/* test if it is already in our thread local cache */
	if((ttile=cache->tiles.first)) {
		/* check last used tile before going to hash */
		if(ttile->ibuf == ibuf && ttile->tx == tx && ttile->ty == ty)
			return ibuf->tiles[toffs];

		/* find tile in hash */
		lookuptile.ibuf = ibuf;
		lookuptile.tx = tx;
		lookuptile.ty = ty;

		if((ttile=BLI_ghash_lookup(cache->tilehash, &lookuptile))) {
			BLI_remlink(&cache->tiles, ttile);
			BLI_addhead(&cache->tiles, ttile);

			return ibuf->tiles[toffs];
		}
	}

	/* not found, have to do slow lookup in global cache */
	if(cache->unused.first == NULL) {
		ttile= cache->tiles.last;
		replacetile= ttile->global;
		BLI_remlink(&cache->tiles, ttile);
		BLI_ghash_remove(cache->tilehash, ttile, NULL, NULL);
	}
	else {
		ttile= cache->unused.first;
		replacetile= NULL;
		BLI_remlink(&cache->unused, ttile);
	}

	BLI_addhead(&cache->tiles, ttile);
	BLI_ghash_insert(cache->tilehash, ttile, ttile);

	gtile= imb_global_cache_get_tile(ibuf, tx, ty, replacetile);

	ttile->ibuf= gtile->ibuf;
	ttile->tx= gtile->tx;
	ttile->ty= gtile->ty;
	ttile->global= gtile;

	return ibuf->tiles[toffs];
}
Ejemplo n.º 20
0
void strand_shade_unref(StrandShadeCache *cache, ObjectInstanceRen *obi, StrandVert *svert)
{
	GHashPair pair = strand_shade_hash_pair(obi, svert);
	int *refcount;

	/* lower reference count and remove if not needed anymore by any samples */
	refcount= BLI_ghash_lookup(cache->refcounthash, &pair);

	(*refcount)--;
	if (*refcount == 0) {
		BLI_ghash_remove(cache->resulthash, &pair, (GHashKeyFreeFP)MEM_freeN, NULL);
		BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL);
	}
}
Ejemplo n.º 21
0
/* assign only one texid per buffer to avoid sampling the same texture twice */
static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, void *key)
{
	if (BLI_ghash_haskey(bindhash, key)) {
		/* Reuse existing texid */
		input->texid = GET_INT_FROM_POINTER(BLI_ghash_lookup(bindhash, key));
	}
	else {
		/* Allocate new texid */
		input->texid = *texid;
		(*texid)++;
		input->bindtex = true;
		BLI_ghash_insert(bindhash, key, SET_INT_IN_POINTER(input->texid));
	}
}
Ejemplo n.º 22
0
Archivo: wm.c Proyecto: mik0001/Blender
MenuType *WM_menutype_find(const char *idname, int quiet)
{
	MenuType* mt;

	if (idname[0]) {
		mt= BLI_ghash_lookup(menutypes_hash, idname);
		if(mt)
			return mt;
	}

	if(!quiet)
		printf("search for unknown menutype %s\n", idname);

	return NULL;
}
Ejemplo n.º 23
0
/**
 * Helper function for #postEditBoneDuplicate,
 * return the destination pchan from the original.
 */
static bPoseChannel *pchan_duplicate_map(const bPose *pose, GHash *name_map, bPoseChannel *pchan_src)
{
	bPoseChannel *pchan_dst = NULL;
	const char *name_src = pchan_src->name;
	const char *name_dst = BLI_ghash_lookup(name_map, name_src);
	if (name_dst) {
		pchan_dst = BKE_pose_channel_find_name(pose, name_dst);
	}

	if (pchan_dst == NULL) {
		pchan_dst = pchan_src;
	}

	return pchan_dst;
}
Ejemplo n.º 24
0
static void strand_shade_refcount(StrandShadeCache *cache, StrandSegment *sseg, StrandVert *svert)
{
	GHashPair pair = strand_shade_hash_pair(sseg->obi, svert);
	GHashPair *key;
	int *refcount= BLI_ghash_lookup(cache->refcounthash, &pair);

	if (!refcount) {
		key= BLI_memarena_alloc(cache->memarena, sizeof(GHashPair));
		*key = pair;
		refcount= BLI_memarena_alloc(cache->memarena, sizeof(int));
		*refcount= 1;
		BLI_ghash_insert(cache->refcounthash, key, refcount);
	}
	else
		(*refcount)++;
}
Ejemplo n.º 25
0
static void setMPolyMaterial(ExportMeshData *export_data,
                             MPoly *mpoly,
                             int which_orig_mesh)
{
	Object *orig_object;
	GHash *material_hash;
	Material *orig_mat;

	if (which_orig_mesh == CARVE_MESH_LEFT) {
		/* No need to change materian index for faces from left operand */
		return;
	}

	material_hash = export_data->material_hash;
	orig_object = which_object(export_data, which_orig_mesh);

	/* Set material, based on lookup in hash table. */
	orig_mat = give_current_material(orig_object, mpoly->mat_nr + 1);

	if (orig_mat) {
		/* For faces from right operand check if there's requested material
		 * in the left operand. And if it is, use index of that material,
		 * otherwise fallback to first material (material with index=0).
		 */
		if (!BLI_ghash_haskey(material_hash, orig_mat)) {
			int a, mat_nr;

			mat_nr = 0;
			for (a = 0; a < export_data->ob_left->totcol; a++) {
				if (give_current_material(export_data->ob_left, a + 1) == orig_mat) {
					mat_nr = a;
					break;
				}
			}

			BLI_ghash_insert(material_hash, orig_mat, SET_INT_IN_POINTER(mat_nr));

			mpoly->mat_nr = mat_nr;
		}
		else
			mpoly->mat_nr = GET_INT_FROM_POINTER(BLI_ghash_lookup(material_hash, orig_mat));
	}
	else {
		mpoly->mat_nr = 0;
	}
}
Ejemplo n.º 26
0
uiListType *WM_uilisttype_find(const char *idname, bool quiet)
{
	uiListType *ult;

	if (idname[0]) {
		ult = BLI_ghash_lookup(uilisttypes_hash, idname);
		if (ult) {
			return ult;
		}
	}

	if (!quiet) {
		printf("search for unknown uilisttype %s\n", idname);
	}

	return NULL;
}
Ejemplo n.º 27
0
int sample_sss(Render *re, Material *mat, const float co[3], float color[3])
{
	if (re->sss_hash) {
		SSSData *sss= BLI_ghash_lookup(re->sss_hash, mat);

		if (sss) {
			scatter_tree_sample(sss->tree, co, color);
			return 1;
		}
		else {
			color[0]= 0.0f;
			color[1]= 0.0f;
			color[2]= 0.0f;
		}
	}

	return 0;
}
Ejemplo n.º 28
0
/* create an id for a new icon and make sure that ids from deleted icons get reused
 * after the integer number range is used up */
static int get_next_free_id(void)
{
	int startId = gFirstIconId;

	/* if we haven't used up the int number range, we just return the next int */
	if (gNextIconId >= gFirstIconId)
		return gNextIconId++;
	
	/* now we try to find the smallest icon id not stored in the gIcons hash */
	while (BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(startId)) && startId >= gFirstIconId)
		startId++;

	/* if we found a suitable one that isn't used yet, return it */
	if (startId >= gFirstIconId)
		return startId;

	/* fail */
	return 0;
}
Ejemplo n.º 29
0
void BKE_icon_changed(int id)
{
	Icon *icon = NULL;
	
	if (!id || G.background) return;

	icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(id));
	
	if (icon) {
		PreviewImage *prv = BKE_previewimg_id_ensure((ID *)icon->obj);

		/* all previews changed */
		if (prv) {
			int i;
			for (i = 0; i < NUM_ICON_SIZES; ++i) {
				prv->flag[i] |= PRV_CHANGED;
				prv->changed_timestamp[i]++;
			}
		}
	}
}
Ejemplo n.º 30
0
const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *msgid)
{
#define STATIC_LOCALE_SIZE 32  /* Should be more than enough! */

	GHashKey *key;
	static char locale[STATIC_LOCALE_SIZE] = "";
	const char *tmp;

	/* Just in case, should never happen! */
	if (!_translations)
		return msgid;

	tmp = BLF_lang_get();
	if (strcmp(tmp, locale) || !_translations_cache) {
		PyGILState_STATE _py_state;

		BLI_strncpy(locale, tmp, STATIC_LOCALE_SIZE);

		/* Locale changed or cache does not exist, refresh the whole cache! */
		/* This func may be called from C (i.e. outside of python interpreter 'context'). */
		_py_state = PyGILState_Ensure();

		_build_translations_cache(_translations->py_messages, locale);

		PyGILState_Release(_py_state);
	}

	/* And now, simply create the key (context, messageid) and find it in the cached dict! */
	key = _ghashutil_keyalloc(msgctxt, msgid);

	tmp = BLI_ghash_lookup(_translations_cache, key);

	_ghashutil_keyfree((void *)key);

	return tmp ? tmp : msgid;

#undef STATIC_LOCALE_SIZE
}