Changes in double side lighting usage
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 25 Feb 2012 18:09:39 +0000 (18:09 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 25 Feb 2012 18:09:39 +0000 (18:09 +0000)
Disabled double-side lighting by default and changed areas which are using
double sided lighting to switch it off just after doing stuff which requires
double side.

This makes code a bit more simple to follow (no all that disabling double side
lighting all over the code and so).

This change also fixes crash of blender caused by intel gme965 driver which
leads to stack corruption in some place when double side lighting isn't
disabled (probably driver still kind of using double side in some areas or so).

Hopefully it'll also fix #30293: Converting Text to Mesh

Thanks to Campbell to assist writing this patch!

source/blender/editors/space_view3d/drawobject.c
source/blender/gpu/intern/gpu_extensions.c

index 1c666e7eda5de26c589b740cd6fd469aaedb0a98..2abfb9bac98d6e004284b3f2594254a1b57950f2 100644 (file)
@@ -3021,6 +3021,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
 
                        glFrontFace(GL_CCW);
                        glDisable(GL_LIGHTING);
+                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                }
                        
                // Setup for drawing wire over, disable zbuffer
@@ -3365,6 +3366,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glFrontFace(GL_CCW);
                        glDisable(GL_LIGHTING);
 
+                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+
                        if (base->flag & SELECT) {
                                UI_ThemeColor(is_obact ? TH_ACTIVE : TH_SELECT);
                        }
@@ -3804,7 +3807,6 @@ static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, B
                GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
 
                if (!glsl) {
-                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                        glEnable(GL_LIGHTING);
                        dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
                        glDisable(GL_LIGHTING);
@@ -3866,7 +3868,6 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                                }
                                else {
                                        GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
-                                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                        drawDispListsolid(lb, ob, 0);
                                        GPU_end_object_materials();
                                }
@@ -3904,7 +3905,6 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                        }
                        else {
                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
-                               glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                drawDispListsolid(lb, ob, 0);
                                GPU_end_object_materials();
                        }
@@ -3929,7 +3929,6 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                                }
                                else {
                                        GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
-                                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                                        drawDispListsolid(lb, ob, 0);
                                        GPU_end_object_materials();
                                }
@@ -7329,7 +7328,6 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *r
                        glDisable(GL_COLOR_MATERIAL);
                }
                
-               glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
                glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
                glEnable(GL_LIGHTING);
                
index a3e3eb19a5b2cd89afe9b656a7078e1975eeb894..002563ada4b8d7b2585bd5db5323adf63a88ed03 100644 (file)
@@ -179,6 +179,10 @@ void GPU_extensions_init(void)
                        GG.npotdisabled = 1;
        }
 
+       /* make sure double side isn't used by defautl and only getting enabled in places where it's
+        * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */
+       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+
        GG.os = GPU_OS_UNIX;
 #ifdef _WIN32
        GG.os = GPU_OS_WIN;