Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-25 13:26:47 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2012-05-25 13:26:47 +0400
commit19dd66cf3b0108c0a74d7626b31c1b8cb9dd57fe (patch)
treeef7c42022e4adddf82a0bc5929f30d61aa976354 /source
parent29e89dc996c0addbc36b4d0051760842b4923bb6 (diff)
3D View: add Backface Culling option, to hide faces when seen from the back side,
found in the Display panel. Patch by Simon Kirk and Irie Shinsuke, refactored to also work for non-mesh objects and avoid globals.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_view3d/drawobject.c24
-rw-r--r--source/blender/gpu/intern/gpu_draw.c14
-rw-r--r--source/blender/makesdna/DNA_view3d_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_space.c5
4 files changed, 43 insertions, 1 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 780f4a2d86a..a5f3df4257a 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -3610,7 +3610,13 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
else if (ob->modifiers.first || obedit->modifiers.first) {}
else drawlinked = 1;
}
-
+
+ /* backface culling */
+ if (v3d->flag2 & V3D_BACKFACE_CULLING) {
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ }
+
if (ob == obedit || drawlinked) {
DerivedMesh *finalDM, *cageDM;
@@ -3669,6 +3675,9 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
}
}
}
+
+ if (v3d->flag2 & V3D_BACKFACE_CULLING)
+ glDisable(GL_CULL_FACE);
return retval;
}
@@ -3939,7 +3948,17 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
const short solid = (dt > OB_WIRE);
int retval = 0;
+ /* backface culling */
+ if(v3d->flag2 & V3D_BACKFACE_CULLING) {
+ /* not all displists use same in/out normal direction convention */
+ glEnable(GL_CULL_FACE);
+ glCullFace((ob->type == OB_MBALL) ? GL_BACK : GL_FRONT);
+ }
+
if (drawCurveDerivedMesh(scene, v3d, rv3d, base, dt) == 0) {
+ if (v3d->flag2 & V3D_BACKFACE_CULLING)
+ glDisable(GL_CULL_FACE);
+
return 0;
}
@@ -4045,6 +4064,9 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
break;
}
+ if (v3d->flag2 & V3D_BACKFACE_CULLING)
+ glDisable(GL_CULL_FACE);
+
return retval;
}
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 604e8f8d50e..fb277815878 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -1017,6 +1017,8 @@ static struct GPUMaterialState {
float (*gviewmat)[4];
float (*gviewinv)[4];
+ int backface_culling;
+
GPUBlendMode *alphablend;
GPUBlendMode alphablend_fixed[FIXEDMAT];
int use_alpha_pass, is_alpha_pass;
@@ -1085,6 +1087,8 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
GMS.lastretval = -1;
GMS.lastalphablend = GPU_BLEND_SOLID;
+ GMS.backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING);
+
GMS.gob = ob;
GMS.gscene = scene;
GMS.totmat= ob->totcol+1; /* materials start from 1, default material is 0 */
@@ -1248,6 +1252,13 @@ int GPU_enable_material(int nr, void *attribs)
alphablend= mat->game.alpha_blend;
if (GMS.is_alpha_pass) glDepthMask(1);
+
+ if (GMS.backface_culling) {
+ if(mat->game.flag)
+ glEnable(GL_CULL_FACE);
+ else
+ glDisable(GL_CULL_FACE);
+ }
}
else {
/* or do fixed function opengl material */
@@ -1283,6 +1294,9 @@ void GPU_disable_material(void)
GMS.lastretval= 1;
if (GMS.gboundmat) {
+ if (GMS.backface_culling)
+ glDisable(GL_CULL_FACE);
+
if (GMS.is_alpha_pass) glDepthMask(0);
GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat));
GMS.gboundmat= NULL;
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index fb4d4202b31..e89cc751a69 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -266,6 +266,7 @@ typedef struct View3D {
#define V3D_SHOW_RECONSTRUCTION 128
#define V3D_SHOW_CAMERAPATH 256
#define V3D_SHOW_BUNDLENAME 512
+#define V3D_BACKFACE_CULLING 1024
/* View3D->around */
#define V3D_CENTER 0
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index e4d380ef48c..9b4dcd03c79 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1567,6 +1567,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
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, "show_backface_culling", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_BACKFACE_CULLING);
+ RNA_def_property_ui_text(prop, "Backface Culling", "Use back face culling to hide the back side of faces");
+ 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");