~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/render/render_update.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
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"
46
47
 
47
48
#include "BKE_context.h"
48
49
#include "BKE_depsgraph.h"
 
50
#include "BKE_DerivedMesh.h"
49
51
#include "BKE_icons.h"
50
52
#include "BKE_image.h"
51
53
#include "BKE_main.h"
56
58
#include "BKE_world.h"
57
59
 
58
60
#include "GPU_material.h"
 
61
#include "GPU_buffers.h"
59
62
 
60
63
#include "RE_engine.h"
 
64
#include "RE_pipeline.h"
61
65
 
62
66
#include "ED_node.h"
63
67
#include "ED_render.h"
64
68
 
65
69
#include "render_intern.h"  // own include
66
70
 
 
71
extern Material defmaterial;
 
72
 
67
73
/***************************** Render Engines ********************************/
68
74
 
69
75
void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
74
80
        bScreen *sc;
75
81
        ScrArea *sa;
76
82
        ARegion *ar;
 
83
        static int recursive_check = FALSE;
77
84
 
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())
81
88
                return;
82
89
 
 
90
        /* don't call this recursively for frame updates */
 
91
        if (recursive_check)
 
92
                return;
 
93
        
 
94
        recursive_check = TRUE;
 
95
 
83
96
        C = CTX_create();
84
97
        CTX_data_main_set(C, bmain);
85
98
        CTX_data_scene_set(C, scene);
114
127
        }
115
128
 
116
129
        CTX_free(C);
 
130
 
 
131
        recursive_check = FALSE;
117
132
}
118
133
 
119
134
void ED_render_engine_area_exit(ScrArea *sa)
127
142
        for (ar = sa->regionbase.first; ar; ar = ar->next) {
128
143
                RegionView3D *rv3d;
129
144
 
130
 
                if (ar->regiontype != RGN_TYPE_WINDOW)
 
145
                if (ar->regiontype != RGN_TYPE_WINDOW || !(ar->regiondata))
131
146
                        continue;
132
147
                
133
148
                rv3d = ar->regiondata;
144
159
        /* on changing the render engine type, clear all running render engines */
145
160
        bScreen *sc;
146
161
        ScrArea *sa;
 
162
        Scene *scene;
147
163
 
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);
 
167
 
 
168
        RE_FreePersistentData();
 
169
 
 
170
        for (scene = bmain->scene.first; scene; scene = scene->id.next)
 
171
                ED_render_id_flush_update(bmain, &scene->id);
151
172
}
152
173
 
153
174
/***************************** Updates ***********************************
214
235
static void material_changed(Main *bmain, Material *ma)
215
236
{
216
237
        Material *parent;
 
238
        Object *ob;
 
239
        Scene *scene;
 
240
        int texture_draw = FALSE;
217
241
 
218
242
        /* icons */
219
243
        BKE_icon_changed(BKE_icon_getid(&ma->id));
224
248
 
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)) ;
228
 
                else continue;
 
251
                if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) {
 
252
                        /* pass */
 
253
                }
 
254
                else {
 
255
                        continue;
 
256
                }
229
257
 
230
258
                BKE_icon_changed(BKE_icon_getid(&parent->id));
231
259
 
232
260
                if (parent->gpumaterial.first)
233
261
                        GPU_material_free(parent);
234
262
        }
 
263
 
 
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) {
 
267
                        texture_draw = TRUE;
 
268
                        break;
 
269
                }
 
270
        }
 
271
 
 
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);
 
278
 
 
279
                        if (dm && totmaterial && material) {
 
280
                                for (a = 0; a < *totmaterial; a++) {
 
281
                                        if ((*material)[a] == ma) {
 
282
                                                GPU_drawobject_free(dm);
 
283
                                                break;
 
284
                                        }
 
285
                                }
 
286
                        }
 
287
                }
 
288
        }
 
289
 
 
290
}
 
291
 
 
292
static void lamp_changed(Main *bmain, Lamp *la)
 
293
{
 
294
        Object *ob;
 
295
        Material *ma;
 
296
 
 
297
        /* icons */
 
298
        BKE_icon_changed(BKE_icon_getid(&la->id));
 
299
 
 
300
        /* glsl */
 
301
        for (ob = bmain->object.first; ob; ob = ob->id.next)
 
302
                if (ob->data == la && ob->gpulamp.first)
 
303
                        GPU_lamp_free(ob);
 
304
 
 
305
        for (ma = bmain->mat.first; ma; ma = ma->id.next)
 
306
                if (ma->gpumaterial.first)
 
307
                        GPU_material_free(ma);
 
308
 
 
309
        if (defmaterial.gpumaterial.first)
 
310
                GPU_material_free(&defmaterial);
 
311
}
 
312
 
 
313
static int material_uses_texture(Material *ma, Tex *tex)
 
314
{
 
315
        if (mtex_use_tex(ma->mtex, MAX_MTEX, tex))
 
316
                return TRUE;
 
317
        else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex))
 
318
                return TRUE;
 
319
        
 
320
        return FALSE;
235
321
}
236
322
 
237
323
static void texture_changed(Main *bmain, Tex *tex)
240
326
        Lamp *la;
241
327
        World *wo;
242
328
        Scene *scene;
 
329
        Object *ob;
243
330
        bNode *node;
 
331
        int texture_draw = FALSE;
244
332
 
245
333
        /* icons */
246
334
        BKE_icon_changed(BKE_icon_getid(&tex->id));
247
335
 
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)) ;
252
 
                else continue;
 
338
                if (!material_uses_texture(ma, tex))
 
339
                        continue;
253
340
 
254
341
                BKE_icon_changed(BKE_icon_getid(&ma->id));
255
342
 
259
346
 
260
347
        /* find lamps */
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)) ;
264
 
                else continue;
265
 
 
266
 
                BKE_icon_changed(BKE_icon_getid(&la->id));
 
349
                if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) {
 
350
                        lamp_changed(bmain, la);
 
351
                }
 
352
                else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) {
 
353
                        lamp_changed(bmain, la);
 
354
                }
 
355
                else {
 
356
                        continue;
 
357
                }
267
358
        }
268
359
 
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)) ;
273
 
                else continue;
 
362
                if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) {
 
363
                        /* pass */
 
364
                }
 
365
                else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) {
 
366
                        /* pass */
 
367
                }
 
368
                else {
 
369
                        continue;
 
370
                }
274
371
 
275
372
                BKE_icon_changed(BKE_icon_getid(&wo->id));
276
373
        }
283
380
                                        ED_node_changed_update(&scene->id, node);
284
381
                        }
285
382
                }
286
 
        }
287
 
}
288
 
 
289
 
static void lamp_changed(Main *bmain, Lamp *la)
290
 
{
291
 
        Object *ob;
292
 
        Material *ma;
293
 
 
294
 
        /* icons */
295
 
        BKE_icon_changed(BKE_icon_getid(&la->id));
296
 
 
297
 
        /* glsl */
298
 
        for (ob = bmain->object.first; ob; ob = ob->id.next)
299
 
                if (ob->data == la && ob->gpulamp.first)
300
 
                        GPU_lamp_free(ob);
301
 
 
302
 
        for (ma = bmain->mat.first; ma; ma = ma->id.next)
303
 
                if (ma->gpumaterial.first)
304
 
                        GPU_material_free(ma);
 
383
 
 
384
                if (scene->customdata_mask & CD_MASK_MTFACE)
 
385
                        texture_draw = TRUE;
 
386
        }
 
387
 
 
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);
 
394
 
 
395
                        if (dm && totmaterial && material) {
 
396
                                for (a = 0; a < *totmaterial; a++) {
 
397
                                        Material *ma;
 
398
 
 
399
                                        if (ob->matbits && ob->matbits[a])
 
400
                                                ma = ob->mat[a];
 
401
                                        else
 
402
                                                ma = (*material)[a];
 
403
 
 
404
                                        if (ma && material_uses_texture(ma, tex)) {
 
405
                                                GPU_drawobject_free(dm);
 
406
                                                break;
 
407
                                        }
 
408
                                }
 
409
                        }
 
410
                }
 
411
        }
305
412
}
306
413
 
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);
 
425
 
 
426
        if (defmaterial.gpumaterial.first)
 
427
                GPU_material_free(&defmaterial);
318
428
}
319
429
 
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);
 
456
 
 
457
        if (defmaterial.gpumaterial.first)
 
458
                GPU_material_free(&defmaterial);
346
459
}
347
460
 
348
461
void ED_render_id_flush_update(Main *bmain, ID *id)
349
462
{
 
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())
 
467
                return;
 
468
 
350
469
        switch (GS(id->name)) {
351
470
                case ID_MA:
352
471
                        material_changed(bmain, (Material *)id);