Ejemplo n.º 1
0
static void scene_changed(Main *bmain, Scene *scene)
{
	Object *ob;
	Material *ma;
	World *wo;

	/* glsl */
	for (ob = bmain->object.first; ob; ob = ob->id.next) {
		if (ob->gpulamp.first)
			GPU_lamp_free(ob);
		
		if (ob->mode & OB_MODE_TEXTURE_PAINT) {
			BKE_texpaint_slots_refresh_object(scene, ob);
			BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
			GPU_drawobject_free(ob->derivedFinal);
		}
	}

	for (ma = bmain->mat.first; ma; ma = ma->id.next)
		if (ma->gpumaterial.first)
			GPU_material_free(&ma->gpumaterial);

	for (wo = bmain->world.first; wo; wo = wo->id.next)
		if (wo->gpumaterial.first)
			GPU_material_free(&wo->gpumaterial);
	
	if (defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial.gpumaterial);
}
Ejemplo n.º 2
0
static void material_changed(Main *bmain, Material *ma)
{
	Material *parent;
	Object *ob;
	Scene *scene;
	int texture_draw = false;

	/* icons */
	BKE_icon_changed(BKE_icon_id_ensure(&ma->id));

	/* glsl */
	if (ma->gpumaterial.first)
		GPU_material_free(&ma->gpumaterial);

	/* find node materials using this */
	for (parent = bmain->mat.first; parent; parent = parent->id.next) {
		if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) {
			/* pass */
		}
		else {
			continue;
		}

		BKE_icon_changed(BKE_icon_id_ensure(&parent->id));

		if (parent->gpumaterial.first)
			GPU_material_free(&parent->gpumaterial);
	}

	/* find if we have a scene with textured display */
	for (scene = bmain->scene.first; scene; scene = scene->id.next) {
		if (scene->customdata_mask & CD_MASK_MTFACE) {
			texture_draw = true;
			break;
		}
	}

	/* find textured objects */
	if (texture_draw) {
		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			DerivedMesh *dm = ob->derivedFinal;
			Material ***material = give_matarar(ob);
			short a, *totmaterial = give_totcolp(ob);

			if (dm && totmaterial && material) {
				for (a = 0; a < *totmaterial; a++) {
					if ((*material)[a] == ma) {
						GPU_drawobject_free(dm);
						break;
					}
				}
			}
		}
	}

}
Ejemplo n.º 3
0
static void world_changed(Main *bmain, World *wo)
{
	Material *ma;

	/* icons */
	BKE_icon_changed(BKE_icon_getid(&wo->id));

	/* glsl */
	for (ma = bmain->mat.first; ma; ma = ma->id.next)
		if (ma->gpumaterial.first)
			GPU_material_free(ma);

	if (defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial);
}
void GPU_codegen_exit(void)
{
	extern Material defmaterial;    // render module abuse...

	if (defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial);

	if (FUNCTION_HASH) {
		BLI_ghash_free(FUNCTION_HASH, NULL, MEM_freeN);
		FUNCTION_HASH = NULL;
	}

	GPU_shader_free_builtin_shaders();

	if (glsl_material_library) {
		MEM_freeN(glsl_material_library);
		glsl_material_library = NULL;
	}

	/*if (FUNCTION_PROTOTYPES) {
		MEM_freeN(FUNCTION_PROTOTYPES);
		FUNCTION_PROTOTYPES = NULL;
	}*/
	/*if (FUNCTION_LIB) {
		GPU_shader_free(FUNCTION_LIB);
		FUNCTION_LIB = NULL;
	}*/
}
Ejemplo n.º 5
0
void BKE_world_free_ex(World *wrld, bool do_id_user)
{
	MTex *mtex;
	int a;
	
	for (a = 0; a < MAX_MTEX; a++) {
		mtex = wrld->mtex[a];
		if (do_id_user && mtex && mtex->tex) mtex->tex->id.us--;
		if (mtex) MEM_freeN(mtex);
	}
	BKE_previewimg_free(&wrld->preview);

	BKE_animdata_free((ID *)wrld);

	/* is no lib link block, but world extension */
	if (wrld->nodetree) {
		ntreeFreeTree_ex(wrld->nodetree, do_id_user);
		MEM_freeN(wrld->nodetree);
	}

	if (wrld->gpumaterial.first)
		GPU_material_free(&wrld->gpumaterial);
	
	BKE_icon_delete((struct ID *)wrld);
	wrld->id.icon_id = 0;
}
Ejemplo n.º 6
0
/* not material itself */
void free_material(Material *ma)
{
	MTex *mtex;
	int a;
	
	for(a=0; a<MAX_MTEX; a++) {
		mtex= ma->mtex[a];
		if(mtex && mtex->tex) mtex->tex->id.us--;
		if(mtex) MEM_freeN(mtex);
	}
	
	if(ma->ramp_col) MEM_freeN(ma->ramp_col);
	if(ma->ramp_spec) MEM_freeN(ma->ramp_spec);
	
	BKE_free_animdata((ID *)ma);
	
	if(ma->preview)
		BKE_previewimg_free(&ma->preview);
	BKE_icon_delete((struct ID*)ma);
	ma->id.icon_id = 0;
	
	/* is no lib link block, but material extension */
	if(ma->nodetree) {
		ntreeFreeTree(ma->nodetree);
		MEM_freeN(ma->nodetree);
	}

	if(ma->gpumaterial.first)
		GPU_material_free(ma);
}
Ejemplo n.º 7
0
static void scene_changed(Main *bmain, Scene *UNUSED(scene))
{
	Object *ob;
	Material *ma;

	/* glsl */
	for (ob = bmain->object.first; ob; ob = ob->id.next)
		if (ob->gpulamp.first)
			GPU_lamp_free(ob);

	for (ma = bmain->mat.first; ma; ma = ma->id.next)
		if (ma->gpumaterial.first)
			GPU_material_free(ma);

	if (defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial);
}
Ejemplo n.º 8
0
static void lamp_changed(Main *bmain, Lamp *la)
{
	Object *ob;
	Material *ma;

	/* icons */
	BKE_icon_changed(BKE_icon_id_ensure(&la->id));

	/* glsl */
	for (ob = bmain->object.first; ob; ob = ob->id.next)
		if (ob->data == la && ob->gpulamp.first)
			GPU_lamp_free(ob);

	for (ma = bmain->mat.first; ma; ma = ma->id.next)
		if (ma->gpumaterial.first)
			GPU_material_free(&ma->gpumaterial);

	if (defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial.gpumaterial);
}
Ejemplo n.º 9
0
static void material_changed(Main *bmain, Material *ma)
{
	Material *parent;

	/* icons */
	BKE_icon_changed(BKE_icon_getid(&ma->id));

	/* glsl */
	if (ma->gpumaterial.first)
		GPU_material_free(ma);

	/* find node materials using this */
	for (parent = bmain->mat.first; parent; parent = parent->id.next) {
		if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) ;
		else continue;

		BKE_icon_changed(BKE_icon_getid(&parent->id));

		if (parent->gpumaterial.first)
			GPU_material_free(parent);
	}
}
Ejemplo n.º 10
0
static void texture_changed(Main *bmain, Tex *tex)
{
	Material *ma;
	Lamp *la;
	World *wo;
	Scene *scene;
	bNode *node;

	/* icons */
	BKE_icon_changed(BKE_icon_getid(&tex->id));

	/* find materials */
	for (ma = bmain->mat.first; ma; ma = ma->id.next) {
		if (mtex_use_tex(ma->mtex, MAX_MTEX, tex)) ;
		else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex)) ;
		else continue;

		BKE_icon_changed(BKE_icon_getid(&ma->id));

		if (ma->gpumaterial.first)
			GPU_material_free(ma);
	}

	/* find lamps */
	for (la = bmain->lamp.first; la; la = la->id.next) {
		if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) ;
		else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) ;
		else continue;

		BKE_icon_changed(BKE_icon_getid(&la->id));
	}

	/* find worlds */
	for (wo = bmain->world.first; wo; wo = wo->id.next) {
		if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) ;
		else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) ;
		else continue;

		BKE_icon_changed(BKE_icon_getid(&wo->id));
	}

	/* find compositing nodes */
	for (scene = bmain->scene.first; scene; scene = scene->id.next) {
		if (scene->use_nodes && scene->nodetree) {
			for (node = scene->nodetree->nodes.first; node; node = node->next) {
				if (node->id == &tex->id)
					ED_node_changed_update(&scene->id, node);
			}
		}
	}
}
Ejemplo n.º 11
0
void GPU_extensions_exit(void)
{
	extern Material defmaterial;    // render module abuse...

	if(defmaterial.gpumaterial.first)
		GPU_material_free(&defmaterial);

	if(FUNCTION_HASH) {
		BLI_ghash_free(FUNCTION_HASH, NULL, (GHashValFreeFP)MEM_freeN);
		FUNCTION_HASH = NULL;
	}
	/*if(FUNCTION_PROTOTYPES) {
		MEM_freeN(FUNCTION_PROTOTYPES);
		FUNCTION_PROTOTYPES = NULL;
	}*/
	/*if(FUNCTION_LIB) {
		GPU_shader_free(FUNCTION_LIB);
		FUNCTION_LIB = NULL;
	}*/
}
Ejemplo n.º 12
0
static void texture_changed(Main *bmain, Tex *tex)
{
	Material *ma;
	Lamp *la;
	World *wo;
	Scene *scene;
	Object *ob;
	bNode *node;
	bool texture_draw = false;

	/* icons */
	BKE_icon_changed(BKE_icon_id_ensure(&tex->id));

	/* paint overlays */
	for (scene = bmain->scene.first; scene; scene = scene->id.next)
		BKE_paint_invalidate_overlay_tex(scene, tex);

	/* find materials */
	for (ma = bmain->mat.first; ma; ma = ma->id.next) {
		if (!material_uses_texture(ma, tex))
			continue;

		BKE_icon_changed(BKE_icon_id_ensure(&ma->id));

		if (ma->gpumaterial.first)
			GPU_material_free(&ma->gpumaterial);
	}

	/* find lamps */
	for (la = bmain->lamp.first; la; la = la->id.next) {
		if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) {
			lamp_changed(bmain, la);
		}
		else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) {
			lamp_changed(bmain, la);
		}
		else {
			continue;
		}
	}

	/* find worlds */
	for (wo = bmain->world.first; wo; wo = wo->id.next) {
		if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) {
			/* pass */
		}
		else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) {
			/* pass */
		}
		else {
			continue;
		}

		BKE_icon_changed(BKE_icon_id_ensure(&wo->id));
		
		if (wo->gpumaterial.first)
			GPU_material_free(&wo->gpumaterial);		
	}

	/* find compositing nodes */
	for (scene = bmain->scene.first; scene; scene = scene->id.next) {
		if (scene->use_nodes && scene->nodetree) {
			for (node = scene->nodetree->nodes.first; node; node = node->next) {
				if (node->id == &tex->id)
					ED_node_tag_update_id(&scene->id);
			}
		}

		if (scene->customdata_mask & CD_MASK_MTFACE)
			texture_draw = true;
	}

	/* find textured objects */
	if (texture_draw) {
		for (ob = bmain->object.first; ob; ob = ob->id.next) {
			DerivedMesh *dm = ob->derivedFinal;
			Material ***material = give_matarar(ob);
			short a, *totmaterial = give_totcolp(ob);

			if (dm && totmaterial && material) {
				for (a = 0; a < *totmaterial; a++) {
					if (ob->matbits && ob->matbits[a])
						ma = ob->mat[a];
					else
						ma = (*material)[a];

					if (ma && material_uses_texture(ma, tex)) {
						GPU_drawobject_free(dm);
						break;
					}
				}
			}
		}
	}
}