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
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/blender/gpu
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/blender/gpu')
-rw-r--r--source/blender/gpu/intern/gpu_draw.c14
1 files changed, 14 insertions, 0 deletions
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;