OpenSubdiv: Made it a modifier option to enable OSD for viewport
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Aug 2015 15:30:44 +0000 (17:30 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Aug 2015 15:51:18 +0000 (17:51 +0200)
The idea of this commit is to make it so we can enable OpenSubdiv by default
for the release builds but keep it limited to the viewport only for a specific
meshes. This is a temporary solution for until all the needed features are
supported on the OpenSubdiv side.

Flag itself is done as a dedicated field in modifier DNA so we can easily
remove it in the future without ending up with some temporary flag hanging
around forever.

release/scripts/startup/bl_ui/properties_data_modifier.py
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesrna/intern/rna_modifier.c
source/blender/modifiers/intern/MOD_subsurf.c

index 549c75d6fdaf16a51f8adbc63bd36945761aec96..de8617ecc521204760ea39d9d80c009e8841b66c 100644 (file)
@@ -874,6 +874,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.label(text="Options:")
         col.prop(md, "use_subsurf_uv")
         col.prop(md, "show_only_control_edges")
+        if hasattr(md, "use_opensubdiv"):
+            col.prop(md, "use_opensubdiv")
 
     def SURFACE(self, layout, ob, md):
         layout.label(text="Settings are inside the Physics tab")
index d952e68696e83bbb5939eab1b2b0577dcd276f22..bd5ddba9590f7d745dada3d8217981e7eb48df80 100644 (file)
@@ -853,7 +853,7 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
 static void ccgSubSurf__sync(CCGSubSurf *ss)
 {
 #ifdef WITH_OPENSUBDIV
-       if (true) {
+       if (ss->skip_grids) {
                ccgSubSurf__sync_opensubdiv(ss);
        }
        else
index cfc9c32e81ec1691d5ee0be4c2fa1afc6bf5bb9a..019c3e58aa74e8f435e2f162d290d2c9037b5579 100644 (file)
@@ -273,7 +273,6 @@ static int getFaceIndex(CCGSubSurf *ss, CCGFace *f, int S, int x, int y, int edg
        }
 }
 
-#ifndef WITH_OPENSUBDIV
 static void get_face_uv_map_vert(UvVertMap *vmap, struct MPoly *mpoly, struct MLoop *ml, int fi, CCGVertHDL *fverts)
 {
        UvMapVert *v, *nv;
@@ -415,13 +414,12 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm,
 
        return 1;
 }
-#endif  /* WITH_OPENSUBDIV */
 
 #ifdef WITH_OPENSUBDIV
-static void set_subsurf_ccg_uv(CCGSubSurf *ss,
-                               DerivedMesh *dm,
-                               DerivedMesh *result,
-                               int layer_index)
+static void UNUSED_FUNCTION(set_subsurf_osd_ccg_uv)(CCGSubSurf *ss,
+                                                    DerivedMesh *dm,
+                                                    DerivedMesh *result,
+                                                    int layer_index)
 {
        CCGFace **faceMap;
        MTFace *tf;
@@ -498,22 +496,9 @@ static void set_subsurf_ccg_uv(CCGSubSurf *ss,
        }
        MEM_freeN(faceMap);
 }
+#endif  /* WITH_OPENSUBDIV */
 
-static void set_subsurf_uv(CCGSubSurf *ss,
-                           DerivedMesh *dm,
-                           DerivedMesh *result,
-                           int layer_index)
-{
-       if (!ccgSubSurf_needGrids(ss)) {
-               /* GPU backend is used, no need to evaluate UVs on CPU. */
-               /* TODO(sergey): Think of how to support edit mode of UVs. */
-       }
-       else {
-               set_subsurf_ccg_uv(ss, dm, result, layer_index);
-       }
-}
-#else  /* WITH_OPENSUBDIV */
-static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, int n)
+static void set_subsurf_legacy_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, int n)
 {
        CCGSubSurf *uvss;
        CCGFace **faceMap;
@@ -593,7 +578,23 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result,
        ccgSubSurf_free(uvss);
        MEM_freeN(faceMap);
 }
-#endif  /* WITH_OPENSUBDIV */
+
+static void set_subsurf_uv(CCGSubSurf *ss,
+                           DerivedMesh *dm,
+                           DerivedMesh *result,
+                           int layer_index)
+{
+#ifdef WITH_OPENSUBDIV
+       if (!ccgSubSurf_needGrids(ss)) {
+               /* GPU backend is used, no need to evaluate UVs on CPU. */
+               /* TODO(sergey): Think of how to support edit mode of UVs. */
+       }
+       else
+#endif
+       {
+               set_subsurf_legacy_uv(ss, dm, result, layer_index);
+       }
+}
 
 /* face weighting */
 typedef struct FaceVertWeightEntry {
@@ -797,9 +798,9 @@ static void ss_sync_from_derivedmesh(CCGSubSurf *ss,
        /* Reset all related descriptors if actual mesh topology changed or if
         * other evlauation-related settings changed.
         */
-       ccgSubSurf_checkTopologyChanged(ss, dm);
        if (!ccgSubSurf_needGrids(ss)) {
                /* TODO(sergey): Use vertex coordinates and flat subdiv flag. */
+               ccgSubSurf_checkTopologyChanged(ss, dm);
                ss_sync_osd_from_derivedmesh(ss, dm);
        }
        else
index 634159e4e60de27e13a33a4464a425752bac25bd..77b9e290cbfe750109b9bfe5110238be8c981271 100644 (file)
@@ -134,6 +134,7 @@ typedef struct SubsurfModifierData {
        ModifierData modifier;
 
        short subdivType, levels, renderLevels, flags;
+       short use_opensubdiv, pad[3];
 
        void *emCache, *mCache;
 } SubsurfModifierData;
index affaef3aa7b9f3668337dd13b4c1cad58e4aef87..6c595076fbdffe6dda0436b335a9cfb4a0521f25 100644 (file)
@@ -1119,6 +1119,13 @@ static void rna_def_modifier_subsurf(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flags", eSubsurfModifierFlag_SubsurfUv);
        RNA_def_property_ui_text(prop, "Subdivide UVs", "Use subsurf to subdivide UVs");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+#ifdef WITH_OPENSUBDIV
+       prop = RNA_def_property(srna, "use_opensubdiv", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "use_opensubdiv", 1);
+       RNA_def_property_ui_text(prop, "Use OpenSubdiv", "Use OpenSubdiv for the subdivisions (viewport only)");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+#endif
 }
 
 static void rna_def_modifier_generic_map_info(StructRNA *srna)
index ff778e62507448d6576fd8ab2761b7c61ce419c1..2a804b0f7353708290cbbb344381606f362eea72 100644 (file)
@@ -120,7 +120,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        /* TODO(sergey): Not entirely correct, modifiers on top of subsurf
         * could be disabled.
         */
-       if (md->next == NULL && allow_gpu && do_cddm_convert == false) {
+       if (md->next == NULL &&
+           allow_gpu &&
+           do_cddm_convert == false &&
+           smd->use_opensubdiv)
+       {
                if ((DAG_get_eval_flags_for_object(md->scene, ob) & DAG_EVAL_NEED_CPU) == 0) {
                        subsurf_flags |= SUBSURF_USE_GPU_BACKEND;
                }