34
34
#include "DNA_lamp_types.h"
35
35
#include "DNA_material_types.h"
36
#include "DNA_meshdata_types.h"
36
37
#include "DNA_node_types.h"
37
38
#include "DNA_object_types.h"
38
39
#include "DNA_scene_types.h"
56
58
#include "BKE_world.h"
58
60
#include "GPU_material.h"
61
#include "GPU_buffers.h"
60
63
#include "RE_engine.h"
64
#include "RE_pipeline.h"
62
66
#include "ED_node.h"
63
67
#include "ED_render.h"
65
69
#include "render_intern.h" // own include
71
extern Material defmaterial;
67
73
/***************************** Render Engines ********************************/
69
75
void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
83
static int recursive_check = FALSE;
78
85
/* don't do this render engine update if we're updating the scene from
79
86
* other threads doing e.g. rendering or baking jobs */
80
87
if (!BLI_thread_is_main())
90
/* don't call this recursively for frame updates */
94
recursive_check = TRUE;
84
97
CTX_data_main_set(C, bmain);
85
98
CTX_data_scene_set(C, scene);
144
159
/* on changing the render engine type, clear all running render engines */
148
164
for (sc = bmain->screen.first; sc; sc = sc->id.next)
149
165
for (sa = sc->areabase.first; sa; sa = sa->next)
150
166
ED_render_engine_area_exit(sa);
168
RE_FreePersistentData();
170
for (scene = bmain->scene.first; scene; scene = scene->id.next)
171
ED_render_id_flush_update(bmain, &scene->id);
153
174
/***************************** Updates ***********************************
225
249
/* find node materials using this */
226
250
for (parent = bmain->mat.first; parent; parent = parent->id.next) {
227
if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) ;
251
if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) {
230
258
BKE_icon_changed(BKE_icon_getid(&parent->id));
232
260
if (parent->gpumaterial.first)
233
261
GPU_material_free(parent);
264
/* find if we have a scene with textured display */
265
for (scene = bmain->scene.first; scene; scene = scene->id.next) {
266
if (scene->customdata_mask & CD_MASK_MTFACE) {
272
/* find textured objects */
273
if (texture_draw && !(U.gameflags & USER_DISABLE_VBO)) {
274
for (ob = bmain->object.first; ob; ob = ob->id.next) {
275
DerivedMesh *dm = ob->derivedFinal;
276
Material ***material = give_matarar(ob);
277
short a, *totmaterial = give_totcolp(ob);
279
if (dm && totmaterial && material) {
280
for (a = 0; a < *totmaterial; a++) {
281
if ((*material)[a] == ma) {
282
GPU_drawobject_free(dm);
292
static void lamp_changed(Main *bmain, Lamp *la)
298
BKE_icon_changed(BKE_icon_getid(&la->id));
301
for (ob = bmain->object.first; ob; ob = ob->id.next)
302
if (ob->data == la && ob->gpulamp.first)
305
for (ma = bmain->mat.first; ma; ma = ma->id.next)
306
if (ma->gpumaterial.first)
307
GPU_material_free(ma);
309
if (defmaterial.gpumaterial.first)
310
GPU_material_free(&defmaterial);
313
static int material_uses_texture(Material *ma, Tex *tex)
315
if (mtex_use_tex(ma->mtex, MAX_MTEX, tex))
317
else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex))
237
323
static void texture_changed(Main *bmain, Tex *tex)
331
int texture_draw = FALSE;
246
334
BKE_icon_changed(BKE_icon_getid(&tex->id));
248
336
/* find materials */
249
337
for (ma = bmain->mat.first; ma; ma = ma->id.next) {
250
if (mtex_use_tex(ma->mtex, MAX_MTEX, tex)) ;
251
else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex)) ;
338
if (!material_uses_texture(ma, tex))
254
341
BKE_icon_changed(BKE_icon_getid(&ma->id));
261
348
for (la = bmain->lamp.first; la; la = la->id.next) {
262
if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) ;
263
else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) ;
266
BKE_icon_changed(BKE_icon_getid(&la->id));
349
if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) {
350
lamp_changed(bmain, la);
352
else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) {
353
lamp_changed(bmain, la);
269
360
/* find worlds */
270
361
for (wo = bmain->world.first; wo; wo = wo->id.next) {
271
if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) ;
272
else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) ;
362
if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) {
365
else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) {
275
372
BKE_icon_changed(BKE_icon_getid(&wo->id));
283
380
ED_node_changed_update(&scene->id, node);
289
static void lamp_changed(Main *bmain, Lamp *la)
295
BKE_icon_changed(BKE_icon_getid(&la->id));
298
for (ob = bmain->object.first; ob; ob = ob->id.next)
299
if (ob->data == la && ob->gpulamp.first)
302
for (ma = bmain->mat.first; ma; ma = ma->id.next)
303
if (ma->gpumaterial.first)
304
GPU_material_free(ma);
384
if (scene->customdata_mask & CD_MASK_MTFACE)
388
/* find textured objects */
389
if (texture_draw && !(U.gameflags & USER_DISABLE_VBO)) {
390
for (ob = bmain->object.first; ob; ob = ob->id.next) {
391
DerivedMesh *dm = ob->derivedFinal;
392
Material ***material = give_matarar(ob);
393
short a, *totmaterial = give_totcolp(ob);
395
if (dm && totmaterial && material) {
396
for (a = 0; a < *totmaterial; a++) {
399
if (ob->matbits && ob->matbits[a])
404
if (ma && material_uses_texture(ma, tex)) {
405
GPU_drawobject_free(dm);
307
414
static void world_changed(Main *bmain, World *wo)
315
422
for (ma = bmain->mat.first; ma; ma = ma->id.next)
316
423
if (ma->gpumaterial.first)
317
424
GPU_material_free(ma);
426
if (defmaterial.gpumaterial.first)
427
GPU_material_free(&defmaterial);
320
430
static void image_changed(Main *bmain, Image *ima)
343
453
for (ma = bmain->mat.first; ma; ma = ma->id.next)
344
454
if (ma->gpumaterial.first)
345
455
GPU_material_free(ma);
457
if (defmaterial.gpumaterial.first)
458
GPU_material_free(&defmaterial);
348
461
void ED_render_id_flush_update(Main *bmain, ID *id)
463
/* this can be called from render or baking thread when a python script makes
464
* changes, in that case we don't want to do any editor updates, and making
465
* GPU changes is not possible because OpenGL only works in the main thread */
466
if (!BLI_thread_is_main())
350
469
switch (GS(id->name)) {
352
471
material_changed(bmain, (Material *)id);