OpenSubdiv: Made it a modifier option to enable OSD for viewport

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.
This commit is contained in:
Sergey Sharybin 2015-08-03 17:30:44 +02:00
parent e90fea72c1
commit 7667ad2d4e
6 changed files with 40 additions and 25 deletions

@ -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")

@ -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

@ -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

@ -134,6 +134,7 @@ typedef struct SubsurfModifierData {
ModifierData modifier;
short subdivType, levels, renderLevels, flags;
short use_opensubdiv, pad[3];
void *emCache, *mCache;
} SubsurfModifierData;

@ -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)

@ -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;
}