Cycles: add python render engine option to use new shading nodes or not, instead
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 11 Oct 2011 17:19:55 +0000 (17:19 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 11 Oct 2011 17:19:55 +0000 (17:19 +0000)
of hardcoded check for cycles. Also some other minor code cleaning tweaks.

25 files changed:
CMakeLists.txt
intern/CMakeLists.txt
intern/cycles/blender/addon/__init__.py
release/scripts/startup/bl_ui/properties_particle.py
release/scripts/startup/bl_ui/properties_texture.py
release/scripts/startup/bl_ui/space_node.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/BKE_scene.h
source/blender/blenkernel/intern/scene.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_node/node_header.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/makesdna/DNA_image_types.h
source/blender/makesdna/DNA_node_types.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_render.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/pipeline/engine.c

index 09acb9e..6bada40 100644 (file)
@@ -1462,12 +1462,6 @@ add_subdirectory(source)
 add_subdirectory(intern)
 add_subdirectory(extern)
 
-#-----------------------------------------------------------------------------
-# Cycles
-
-if(WITH_CYCLES)
-       add_subdirectory(intern/cycles)
-endif()
 
 #-----------------------------------------------------------------------------
 # Blender Application
index fe30d6c..b38b6e1 100644 (file)
@@ -58,3 +58,8 @@ endif()
 if(WITH_IK_ITASC)
        add_subdirectory(itasc)
 endif()
+
+if(WITH_CYCLES)
+       add_subdirectory(cycles)
+endif()
+
index 3ff1a8f..4a5b783 100644 (file)
@@ -40,6 +40,7 @@ from cycles import presets
 class CyclesRender(bpy.types.RenderEngine):
     bl_idname = 'CYCLES'
     bl_label = "Cycles"
+    bl_use_shading_nodes = True
 
     def __init__(self):
         engine.init()
index da4cb05..7f97239 100644 (file)
@@ -41,7 +41,6 @@ def particle_panel_enabled(context, psys):
 
 def particle_panel_poll(cls, context):
     psys = context.particle_system
-    engine = context.scene.render.engine
     settings = 0
 
     if psys:
@@ -79,7 +78,6 @@ class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
 
     @classmethod
     def poll(cls, context):
-        engine = context.scene.render.engine
         return (context.particle_system or context.object or context.space_data.pin_id)
 
     def draw(self, context):
@@ -251,7 +249,6 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         psys = context.particle_system
-        engine = context.scene.render.engine
         if psys is None:
             return False
         if psys.settings is None:
@@ -647,7 +644,6 @@ class PARTICLE_PT_boidbrain(ParticleButtonsPanel, Panel):
     def poll(cls, context):
         psys = context.particle_system
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
 
         if settings is None:
             return False
@@ -746,11 +742,7 @@ class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
-        if settings is None:
-            return False
-
-        return True
+        return settings is not None
 
     def draw(self, context):
         layout = self.layout
@@ -931,10 +923,7 @@ class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
-        if settings is None:
-            return False
-        return True
+        return settings is not None
 
     def draw(self, context):
         layout = self.layout
index 38697c5..34f5a94 100644 (file)
@@ -410,7 +410,6 @@ class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
 
         #Only for Material based textures, not for Lamp/World...
         if slot and isinstance(idblock, bpy.types.Material):
-            slot = context.texture_slot
             col.prop(tex, "use_normal_map")
             row = col.row()
             row.active = tex.use_normal_map
index d46ca25..69766b5 100644 (file)
@@ -27,6 +27,7 @@ class NODE_HT_header(Header):
     def draw(self, context):
         layout = self.layout
 
+        scene = context.scene
         snode = context.space_data
         snode_id = snode.id
         id_from = snode.id_from
@@ -43,9 +44,10 @@ class NODE_HT_header(Header):
         layout.prop(snode, "tree_type", text="", expand=True)
 
         if snode.tree_type == 'SHADER':
-            row.prop(snode, "shader_type", text="", expand=True)
+            if scene.render.use_shading_nodes:
+                layout.prop(snode, "shader_type", text="", expand=True)
 
-            if snode.shader_type == 'OBJECT':
+            if not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT':
                 if id_from:
                     layout.template_ID(id_from, "active_material", new="material.new")
                 if snode_id:
index c35b765..e2fe8c9 100644 (file)
@@ -2142,9 +2142,11 @@ class VIEW3D_PT_view3d_display(Panel):
         subsub.active = scene.unit_settings.system == 'NONE'
         subsub.prop(view, "grid_subdivisions", text="Subdivisions")
 
-        col = layout.column()
-        col.label(text="Shading:")
-        col.prop(gs, "material_mode", text="")
+        if not scene.render.use_shading_nodes:
+            col = layout.column()
+            col.label(text="Shading:")
+            col.prop(gs, "material_mode", text="")
+            col.prop(view, "show_textured_solid")
 
         layout.separator()
 
index 8f85f14..1b12f2d 100644 (file)
@@ -102,7 +102,7 @@ int get_render_child_particle_number(struct RenderData *r, int num);
 int get_render_shadow_samples(struct RenderData *r, int samples);
 float get_render_aosss_error(struct RenderData *r, float error);
 
-int scene_use_new_shading_system(struct Scene *scene);
+int scene_use_new_shading_nodes(struct Scene *scene);
 
 #ifdef __cplusplus
 }
index 7dc5a22..101a109 100644 (file)
@@ -74,6 +74,8 @@
 
 #include "BKE_sound.h"
 
+#include "RE_engine.h"
+
 //XXX #include "BIF_previewrender.h"
 //XXX #include "BIF_editseq.h"
 
@@ -1137,8 +1139,9 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base)
        return NULL;
 }
 
-int scene_use_new_shading_system(Scene *scene)
+int scene_use_new_shading_nodes(Scene *scene)
 {
-       return (strcmp(scene->r.engine, "CYCLES") == 0);
+       RenderEngineType *type= RE_engines_find(scene->r.engine);
+       return (type->flag & RE_USE_SHADING_NODES);
 }
 
index c0ced57..9e12aa6 100644 (file)
@@ -487,7 +487,7 @@ static Image *imapaint_face_image(const ImagePaintState *s, int face_index)
 {
        Image *ima;
 
-       if(scene_use_new_shading_system(s->scene)) {
+       if(scene_use_new_shading_nodes(s->scene)) {
                MFace *mf = s->me->mface+face_index;
                ED_object_get_active_image(s->ob, mf->mat_nr, &ima, NULL);
        }
@@ -503,7 +503,7 @@ static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
 {
        Image *ima;
 
-       if(scene_use_new_shading_system(ps->scene)) {
+       if(scene_use_new_shading_nodes(ps->scene)) {
                MFace *mf = ps->dm_mface+face_index;
                ED_object_get_active_image(ps->ob, mf->mat_nr, &ima, NULL);
        }
index f0709e0..b02b8fd 100644 (file)
@@ -594,7 +594,7 @@ static void image_refresh(const bContext *C, ScrArea *UNUSED(sa))
                EditMesh *em= BKE_mesh_get_editmesh(me);
                int sloppy= 1; /* partially selected face is ok */
 
-               if(scene_use_new_shading_system(scene)) {
+               if(scene_use_new_shading_nodes(scene)) {
                        /* new shading system, get image from material */
                        EditFace *efa= EM_get_actFace(em, sloppy);
 
index 084570d..d5d7929 100644 (file)
@@ -232,7 +232,7 @@ static void node_menu_add(const bContext *C, Menu *menu)
        if(snode->treetype==NTREE_SHADER) {
                uiItemMenuF(layout, IFACE_(N_("Input")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
                uiItemMenuF(layout, IFACE_(N_("Output")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
-               if(scene_use_new_shading_system(scene)) {
+               if(scene_use_new_shading_nodes(scene)) {
                        uiItemMenuF(layout, IFACE_(N_("Shader")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_SHADER));
                        uiItemMenuF(layout, IFACE_(N_("Texture")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_TEXTURE));
                }
index b749538..6cad8f3 100644 (file)
@@ -775,7 +775,7 @@ static int tex_mat_set_face_editmesh_cb(void *UNUSED(userData), int index)
 
 void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int faceselect)
 {
-       if(!scene_use_new_shading_system(scene)) {
+       if(!scene_use_new_shading_nodes(scene)) {
                draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, faceselect);
                return;
        }
index 09ddfd7..5521460 100644 (file)
 
 /* this condition has been made more complex since editmode can draw textures */
 #define CHECK_OB_DRAWTEXTURE(vd, dt) \
-       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID))
+       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) || \
+       (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
 static void draw_bounding_volume(Scene *scene, Object *ob);
 
@@ -131,6 +132,9 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
        if(dt==OB_TEXTURE && vd->drawtype==OB_TEXTURE)
                return 0;
 
+       if(vd->drawtype>=OB_SOLID && vd->flag2 & V3D_SOLID_TEX)
+               return 0;
+
        return 1;
 }
 
@@ -213,7 +217,7 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
                return 0;
        if(ob==OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
                return 0;
-       if(scene_use_new_shading_system(scene))
+       if(scene_use_new_shading_nodes(scene))
                return 0;
        
        return (scene->gm.matmode == GAME_MAT_GLSL) && (dt > OB_SOLID);
index e434610..dba594a 100644 (file)
@@ -2122,6 +2122,7 @@ static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
                
                v3d->drawtype = OB_SOLID;
                v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
+               v3d->flag2 &= ~V3D_SOLID_TEX;
                v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
                
                GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
@@ -2152,7 +2153,7 @@ CustomDataMask ED_view3d_datamask(Scene *scene, View3D *v3d)
 {
        CustomDataMask mask= 0;
 
-       if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL)) {
+       if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) || ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX))) {
                mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
 
                if(v3d->drawtype == OB_MATERIAL || scene->gm.matmode == GAME_MAT_GLSL)
index e80b63b..568445b 100644 (file)
@@ -154,7 +154,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im
                return;
        }
 
-       if(scene_use_new_shading_system(scene)) {
+       if(scene_use_new_shading_nodes(scene)) {
                /* new shading system, assign image in material */
                int sloppy= 1;
                EditFace *efa= EM_get_actFace(em, sloppy);
index e090abe..dd03333 100644 (file)
@@ -42,6 +42,7 @@ struct ImBuf;
 struct RenderResult;
 struct GPUTexture;
 
+
 /* ImageUser is in Texture, in Nodes, Background Image, Image Window, .... */
 /* should be used in conjunction with an ID * to Image. */
 typedef struct ImageUser {
index 3477be4..6d1ff8d 100644 (file)
@@ -104,7 +104,7 @@ typedef struct bNodeSocket {
 #define SOCK_FLOAT                     0
 #define SOCK_VECTOR                    1
 #define SOCK_RGBA                      2
-#define        SOCK_SHADER                     3
+#define SOCK_SHADER                    3
 #define SOCK_BOOLEAN           4
 #define SOCK_MESH                      5
 #define SOCK_INT                       6
index 6d4a845..2b7f54e 100644 (file)
@@ -246,7 +246,7 @@ typedef struct View3D {
 
 /* View3d->flag2 (short) */
 #define V3D_RENDER_OVERRIDE            4
-#define V3D_SOLID_TEX                  8       /* deprecated */
+#define V3D_SOLID_TEX                  8
 #define V3D_DISPGP                             16
 #define V3D_LOCK_CAMERA                        32
 #define V3D_RENDER_SHADOW              64 /* This is a runtime only flag that's used to tell draw_mesh_object() that we're doing a shadow pass instead of a regular draw */
index e64c5fd..8047b2d 100644 (file)
@@ -1454,7 +1454,7 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR
  * but this isnt likely to be a performance problem. */
 int RNA_property_update_check(PropertyRNA *prop)
 {
-       return ((prop->magic != RNA_MAGIC) || prop->update || prop->noteflag);
+       return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
 }
 
 void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
index 460d7ce..ef2e97c 100644 (file)
@@ -397,11 +397,15 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_REGISTER);
 
        prop= RNA_def_property(srna, "bl_use_preview", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_DO_PREVIEW);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_PREVIEW);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        prop= RNA_def_property(srna, "bl_use_postprocess", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_DO_ALL);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_USE_POSTPROCESS);
+       RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
+       prop= RNA_def_property(srna, "bl_use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_SHADING_NODES);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        RNA_define_verify_sdna(1);
index c7a5d2c..42ebdcb 100644 (file)
@@ -841,6 +841,12 @@ static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
        return (BLI_countlist(&R_engines) > 1);
 }
 
+static int rna_RenderSettings_use_shading_nodes_get(PointerRNA *ptr)
+{
+       Scene *scene= (Scene*)ptr->id.data;
+       return scene_use_new_shading_nodes(scene);
+}
+
 static int rna_RenderSettings_use_game_engine_get(PointerRNA *ptr)
 {
        RenderData *rd= (RenderData*)ptr->data;
@@ -3230,6 +3236,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Multiple Engines", "More than one rendering engine is available");
 
+       prop= RNA_def_property(srna, "use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_shading_nodes_get", NULL);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Use Shading Nodes", "Active render engine uses new shading nodes system");
+
        prop= RNA_def_property(srna, "use_game_engine", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_game_engine_get", NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
index b4bda04..8279bdc 100644 (file)
@@ -1373,6 +1373,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Relationship Lines", "Show dashed lines indicating parent or constraint relationships");
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
        
+       prop= RNA_def_property(srna, "show_textured_solid", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SOLID_TEX);
+       RNA_def_property_ui_text(prop, "Textured Solid", "Display face-assigned textures in solid view");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+
        prop= RNA_def_property(srna, "lock_camera", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_LOCK_CAMERA);
        RNA_def_property_ui_text(prop, "Lock Camera to View", "Enable view navigation within the camera view");
index 7f01bc6..7d5ba28 100644 (file)
@@ -48,10 +48,11 @@ struct Scene;
 
 /* External Engine */
 
-#define RE_INTERNAL                    1
-#define RE_GAME                                2
-#define RE_DO_PREVIEW          4
-#define RE_DO_ALL                      8
+#define RE_INTERNAL                            1
+#define RE_GAME                                        2
+#define RE_USE_PREVIEW                 4
+#define RE_USE_POSTPROCESS             8
+#define RE_USE_SHADING_NODES   16
 
 extern ListBase R_engines;
 
index 0fc6a03..d67cd3c 100644 (file)
@@ -268,11 +268,11 @@ int RE_engine_render(Render *re, int do_all)
        /* verify if we can render */
        if(!type->render)
                return 0;
-       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
+       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW))
                return 0;
-       if(do_all && !(type->flag & RE_DO_ALL))
+       if(do_all && !(type->flag & RE_USE_POSTPROCESS))
                return 0;
-       if(!do_all && (type->flag & RE_DO_ALL))
+       if(!do_all && (type->flag & RE_USE_POSTPROCESS))
                return 0;
 
        /* create render result */