Flat shading for basic shader
authorAlexander Romanov <a.romanov@blend4web.com>
Mon, 16 May 2016 08:13:21 +0000 (11:13 +0300)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 9 Jun 2016 19:38:17 +0000 (05:38 +1000)
The purpose of the patch is to replace deprecated  glShadeModel.

To decrease glShadeModel calls I've set GL_SMOOTH by default

Reviewers: merwin, brecht

Reviewed By: brecht

Subscribers: blueprintrandom, Evgeny_Rodygin, AlexKowel, yurikovelenov

Differential Revision: https://developer.blender.org/D1958

22 files changed:
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/editors/gpencil/drawgpencil.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/interface/interface_panel.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/editors/space_view3d/drawanimviz.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/gpu/GPU_basic_shader.h
source/blender/gpu/intern/gpu_basic_shader.c
source/blender/gpu/intern/gpu_buffers.c
source/blender/gpu/intern/gpu_draw.c
source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
source/blender/gpu/shaders/gpu_shader_basic_vert.glsl

index 0de0e4d7797f02b11b23ac5eb4450e9a5deab00c..d590a35bb578b2f33cea5f3d222329637eb66ecc 100644 (file)
@@ -3881,7 +3881,6 @@ static void navmesh_drawColored(DerivedMesh *dm)
        /* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */
        {
                DEBUG_VBO("Using legacy code. drawNavMeshColored\n");
-               //glShadeModel(GL_SMOOTH);
                glBegin(glmode = GL_QUADS);
                for (a = 0; a < dm->numTessFaceData; a++, mface++) {
                        int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
index 392a38773e7c956c95362db02c45d6485628498a..267f7a65e008bbe7dae966fc512f81327bcced43 100644 (file)
@@ -464,7 +464,6 @@ static void cdDM_drawFacesSolid(
 
                        BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
                                      setMaterial, false, false);
-                       glShadeModel(GL_FLAT);
                        return;
                }
        }
@@ -472,7 +471,6 @@ static void cdDM_drawFacesSolid(
        GPU_vertex_setup(dm);
        GPU_normal_setup(dm);
        GPU_triangle_setup(dm);
-       glShadeModel(GL_SMOOTH);
        for (a = 0; a < dm->drawObject->totmaterial; a++) {
                if (!setMaterial || setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) {
                        GPU_buffer_draw_elements(
@@ -481,8 +479,6 @@ static void cdDM_drawFacesSolid(
                }
        }
        GPU_buffers_unbind();
-
-       glShadeModel(GL_FLAT);
 }
 
 static void cdDM_drawFacesTex_common(
@@ -553,8 +549,7 @@ static void cdDM_drawFacesTex_common(
        if (mloopcol) {
                GPU_color_setup(dm, colType);
        }
-               
-       glShadeModel(GL_SMOOTH);
+
        /* lastFlag = 0; */ /* UNUSED */
        for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
                GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
@@ -633,7 +628,6 @@ static void cdDM_drawFacesTex_common(
        }
 
        GPU_buffers_unbind();
-       glShadeModel(GL_FLAT);
        
 }
 
@@ -742,9 +736,6 @@ static void cdDM_drawMappedFaces(
                        }
                }
        }
-               
-
-       glShadeModel(GL_SMOOTH);
 
        tot_tri_elem = dm->drawObject->tot_triangle_point;
 
@@ -841,7 +832,6 @@ static void cdDM_drawMappedFaces(
        }
 
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-       glShadeModel(GL_FLAT);
 
        GPU_buffers_unbind();
 
@@ -929,8 +919,6 @@ static void cdDM_drawMappedFacesGLSL(
        matnr = -1;
        do_draw = false;
 
-       glShadeModel(GL_SMOOTH);
-
        if (setDrawOptions != NULL) {
                DMVertexAttribs attribs;
                DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n");
@@ -1153,8 +1141,6 @@ static void cdDM_drawMappedFacesGLSL(
                MEM_freeN(mat_orig_to_new);
                MEM_freeN(matconv);
        }
-       
-       glShadeModel(GL_FLAT);
 }
 
 static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
@@ -1203,8 +1189,6 @@ static void cdDM_drawMappedFacesMat(
 
        matnr = -1;
 
-       glShadeModel(GL_SMOOTH);
-
        memset(&attribs, 0, sizeof(attribs));
 
        glBegin(GL_TRIANGLES);
@@ -1260,8 +1244,6 @@ static void cdDM_drawMappedFacesMat(
                cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal);
        }
        glEnd();
-
-       glShadeModel(GL_FLAT);
 }
 
 static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData)
index 8df07c5f3f4e22647af46021e06e6144cddfa905..6b81c47765bd508be55b6ecec7f5c86a4b9f8e6b 100644 (file)
@@ -1240,8 +1240,6 @@ static void emDM_drawFacesTex_common(
        // dummylcol.r = dummylcol.g = dummylcol.b = dummylcol.a = 255;  /* UNUSED */
 
        /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
-       glShadeModel(GL_SMOOTH);
-
        BM_mesh_elem_index_ensure(bm, BM_FACE);
 
        /* call again below is ok */
@@ -1388,8 +1386,6 @@ static void emDM_drawFacesTex_common(
                        }
                }
        }
-
-       glShadeModel(GL_FLAT);
 }
 
 static void emDM_drawFacesTex(
@@ -1528,8 +1524,6 @@ static void emDM_drawMappedFacesGLSL(
        vertexNos = bmdm->vertexNos;
        polyNos = bmdm->polyNos;
 
-       /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
-       glShadeModel(GL_SMOOTH);
        BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0));
 
        for (i = 0; i < em->tottri; i++) {
@@ -1640,8 +1634,6 @@ static void emDM_drawMappedFacesMat(
        vertexNos = bmdm->vertexNos;
        polyNos = bmdm->polyNos;
 
-       /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
-       glShadeModel(GL_SMOOTH);
        BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0));
 
        for (i = 0; i < em->tottri; i++) {
index 88bc3fb9854ea65388db1e671693b772f5ea0982..b0d19320230b3b845a8f8a648ec83f3f7aa3cb94 100644 (file)
@@ -2619,7 +2619,6 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
                if (BKE_pbvh_has_faces(ccgdm->pbvh)) {
                        BKE_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL,
                                      setMaterial, false, fast);
-                       glShadeModel(GL_FLAT);
                }
 
                return;
@@ -3164,7 +3163,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
                MEM_freeN(matconv);
        }
 
-       glShadeModel(GL_FLAT);
+       glShadeModel(GL_SMOOTH);
 }
 
 static void ccgDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
index 0329598d711ac7c951d731f9a1ffe7675cbc414b..79a2c4942392d223506495f000d4530e42da97cf 100644 (file)
@@ -763,6 +763,7 @@ static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness
                }
                
                glEnd();
+               glShadeModel(GL_SMOOTH);
        }
        
        /* draw debug points of curve on top? (original stroke points) */
index 8fbc545cb775bd7708e93bf29c53b1a4726a7c1f..d78b41820b4df19816af4fe9a9a4a4d3c7a06143 100644 (file)
@@ -181,7 +181,6 @@ void UI_draw_roundbox_shade_x(
        coldown[1] = max_ff(0.0f, color[1] + shadedown);
        coldown[2] = max_ff(0.0f, color[2] + shadedown);
 
-       glShadeModel(GL_SMOOTH);
        glBegin(mode);
 
        /* start with corner right-bottom */
@@ -260,7 +259,6 @@ void UI_draw_roundbox_shade_x(
        }
        
        glEnd();
-       glShadeModel(GL_FLAT);
 }
 
 /* linear vertical shade within button or in outline */
@@ -291,7 +289,6 @@ void UI_draw_roundbox_shade_y(
        colRight[1] = max_ff(0.0f, color[1] + shadeRight);
        colRight[2] = max_ff(0.0f, color[2] + shadeRight);
 
-       glShadeModel(GL_SMOOTH);
        glBegin(mode);
 
        /* start with corner right-bottom */
@@ -367,7 +364,6 @@ void UI_draw_roundbox_shade_y(
        }
        
        glEnd();
-       glShadeModel(GL_FLAT);
 }
 
 /* plain antialiased unfilled rectangle */
@@ -531,7 +527,6 @@ static void histogram_draw_one(
        }
        else {
                /* under the curve */
-               glShadeModel(GL_FLAT);
                glBegin(GL_TRIANGLE_STRIP);
                glVertex2f(x, y);
                glVertex2f(x, y + (data[0] * h));
@@ -1087,7 +1082,6 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
        /* layer: color ramp */
-       glShadeModel(GL_FLAT);
        glEnable(GL_BLEND);
 
        CBData *cbd = coba->data;
@@ -1133,7 +1127,6 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
        glEnd();
 
        glDisable(GL_BLEND);
-       glShadeModel(GL_SMOOTH);
 
        /* layer: box outline */
        glColor4f(0.0, 0.0, 0.0, 1.0);
@@ -1212,9 +1205,9 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
                
                qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
-               glShadeModel(GL_SMOOTH);
+               int bound_options = GPU_basic_shader_bound_options();
+               GPU_basic_shader_bind(bound_options);
                gluSphere(qobj, 100.0, 32, 24);
-               glShadeModel(GL_FLAT);
                gluDeleteQuadric(qobj);
                
                glEndList();
@@ -1677,7 +1670,6 @@ static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float s
 void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
 {
        glEnable(GL_BLEND);
-       glShadeModel(GL_SMOOTH);
        
        glBegin(GL_QUADS);
 
@@ -1689,7 +1681,6 @@ void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx,
        glEnd();
        
        glDisable(GL_BLEND);
-       glShadeModel(GL_FLAT);
 }
 
 
index 222b0366791dae970c29c1b2d6d48c25ed1c5152..6dc60f1d70b1270cd1befe9de26038413127d1d8 100644 (file)
@@ -368,7 +368,6 @@ static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h),
        viconutil_set_point(pts[1], cx - d2, cy - d);
        viconutil_set_point(pts[2], cx + d2, cy);
 
-       glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glColor4f(0.8f, 0.8f, 0.8f, alpha);
        glVertex2iv(pts[0]);
@@ -376,7 +375,6 @@ static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h),
        glColor4f(0.3f, 0.3f, 0.3f, alpha);
        glVertex2iv(pts[2]);
        glEnd();
-       glShadeModel(GL_FLAT);
 
        glColor4f(0.0f, 0.0f, 0.0f, 1);
        viconutil_draw_lineloop_smooth(pts, 3);
@@ -395,13 +393,11 @@ static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float
 
        glColor4f(0.2f, 0.2f, 0.2f, alpha);
 
-       glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glVertex2iv(pts[0]);
        glVertex2iv(pts[1]);
        glVertex2iv(pts[2]);
        glEnd();
-       glShadeModel(GL_FLAT);
 }
 
 static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha)
@@ -415,7 +411,6 @@ static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), f
        viconutil_set_point(pts[1], cx - d, cy + d2);
        viconutil_set_point(pts[2], cx, cy - d2);
 
-       glShadeModel(GL_SMOOTH);
        glBegin(GL_TRIANGLES);
        glColor4f(0.8f, 0.8f, 0.8f, alpha);
        glVertex2iv(pts[0]);
@@ -423,7 +418,6 @@ static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), f
        glColor4f(0.3f, 0.3f, 0.3f, alpha);
        glVertex2iv(pts[2]);
        glEnd();
-       glShadeModel(GL_FLAT);
 
        glColor4f(0.0f, 0.0f, 0.0f, 1);
        viconutil_draw_lineloop_smooth(pts, 3);
index 62b373c58c8a9346aab7ab36c7f3ac7b7da0472a..85e32144bcdaf7308ee87091216bc455488991c4 100644 (file)
@@ -1763,12 +1763,10 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
                        ui_panel_category_draw_tab(GL_LINE_STRIP, rct->xmin - px, rct->ymin - px, rct->xmax - px, rct->ymax + px,
                                                   tab_curve_radius, roundboxtype, true, true, NULL);
                        /* tab highlight (3d look) */
-                       glShadeModel(GL_SMOOTH);
                        glColor3ubv(is_active ? theme_col_tab_highlight : theme_col_tab_highlight_inactive);
                        ui_panel_category_draw_tab(GL_LINE_STRIP, rct->xmin, rct->ymin, rct->xmax, rct->ymax,
-                                                  tab_curve_radius, roundboxtype, true, false,
-                                                  is_active ? theme_col_back : theme_col_tab_inactive);
-                       glShadeModel(GL_FLAT);
+                                                                          tab_curve_radius, roundboxtype, true, false,
+                                                                          is_active ? theme_col_back : theme_col_tab_inactive);
                }
 
                /* tab blackline */
index 19e0b55374ef93f78578cdeefe01e7e45c407bbc..5098e70163896bb81be773f26b4106d88a7aa3f9 100644 (file)
@@ -712,8 +712,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
                        unsigned char *col_pt = col_array;
                        
                        shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
-                       
-                       glShadeModel(GL_SMOOTH);
+
                        for (a = 0; a < wtb->totvert; a++, col_pt += 4) {
                                round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->draw_shadedir ? 1 : 0]);
                        }
@@ -725,8 +724,6 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
                        glDrawArrays(GL_POLYGON, 0, wtb->totvert);
                        glDisableClientState(GL_VERTEX_ARRAY);
                        glDisableClientState(GL_COLOR_ARRAY);
-
-                       glShadeModel(GL_FLAT);
                }
        }
        
@@ -2311,8 +2308,6 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
        
        ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
 
-       glShadeModel(GL_SMOOTH);
-
        glBegin(GL_TRIANGLE_FAN);
        glColor3fv(colcent);
        glVertex2f(centx, centy);
@@ -2330,8 +2325,6 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
        }
        glEnd();
        
-       glShadeModel(GL_FLAT);
-       
        /* fully rounded outline */
        glPushMatrix();
        glTranslatef(centx, centy, 0.0f);
@@ -2363,7 +2356,6 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
        float col1[4][3];   /* right half, rect bottom to top */
 
        /* draw series of gouraud rects */
-       glShadeModel(GL_SMOOTH);
        
        switch (type) {
                case UI_GRAD_SV:
@@ -2486,8 +2478,6 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
                }
                glEnd();
        }
-
-       glShadeModel(GL_FLAT);
 }
 
 bool ui_but_is_colorpicker_display_space(uiBut *but)
index 9c2d115108d7b244387950442393973d824b7a24..f6afd7a16e7893b8c2817bddf0d8a1f937baa9ad 100644 (file)
@@ -593,7 +593,6 @@ void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, f
        ymid1 = (y2 - y1) * 0.25f + y1;
        ymid2 = (y2 - y1) * 0.65f + y1;
        
-       glShadeModel(GL_SMOOTH);
        glBegin(GL_QUADS);
        
        if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
index 9872b05da63eaca84a70e28210869b6802568e3d..cf738de02026e64267e919a5754ddfc4ac9a467e 100644 (file)
@@ -130,7 +130,6 @@ void draw_motion_path_instance(Scene *scene,
        mpv_start = (mpath->points + sind);
        
        /* draw curve-line of path */
-       glShadeModel(GL_SMOOTH);
        
        glBegin(GL_LINE_STRIP);
        for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
@@ -187,7 +186,6 @@ void draw_motion_path_instance(Scene *scene,
        }
        
        glEnd();
-       glShadeModel(GL_FLAT);
        
        glPointSize(1.0);
        
index 1306e832592bced7944908aca197b83b959ffbdb..1d9a515a5f25e801d0471a839721b6f133e45df0 100644 (file)
@@ -431,10 +431,9 @@ static void draw_bonevert_solid(void)
                glNewList(displist, GL_COMPILE);
                
                qobj = gluNewQuadric();
-               gluQuadricDrawStyle(qobj, GLU_FILL); 
-               glShadeModel(GL_SMOOTH);
+               gluQuadricDrawStyle(qobj, GLU_FILL);
+               /* Draw tips of a bone */
                gluSphere(qobj, 0.05, 8, 5);
-               glShadeModel(GL_FLAT);
                gluDeleteQuadric(qobj);  
                
                glEndList();
@@ -890,7 +889,6 @@ static void draw_sphere_bone(const short dt, int armflag, int boneflag, short co
                GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
                
                gluQuadricDrawStyle(qobj, GLU_FILL); 
-               glShadeModel(GL_SMOOTH);
        }
        else {
                gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
@@ -968,7 +966,6 @@ static void draw_sphere_bone(const short dt, int armflag, int boneflag, short co
        
        /* restore */
        if (dt == OB_SOLID) {
-               glShadeModel(GL_FLAT);
                GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
        }
        
@@ -1770,7 +1767,6 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                /* and draw blended distances */
                if (arm->flag & ARM_POSEMODE) {
                        glEnable(GL_BLEND);
-                       //glShadeModel(GL_SMOOTH);
                        
                        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
                        
@@ -1793,7 +1789,6 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        
                        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
                        glDisable(GL_BLEND);
-                       //glShadeModel(GL_FLAT);
                }
        }
        
@@ -2217,7 +2212,6 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt)
                
                /* and draw blended distances */
                glEnable(GL_BLEND);
-               //glShadeModel(GL_SMOOTH);
                
                if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
 
@@ -2232,7 +2226,6 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt)
                
                if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
                glDisable(GL_BLEND);
-               //glShadeModel(GL_FLAT);
        }
        
        /* if solid we draw it first */
index 883f06763deaa72d3ed62daa028027d8b3a5f472..d8364011036b5383fa480104dc79a61cbe8526e1 100644 (file)
@@ -496,7 +496,6 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
 
        memcpy(Gtexdraw.obcol, obcol, sizeof(obcol));
        set_draw_settings_cached(1, NULL, NULL, Gtexdraw);
-       glShadeModel(GL_SMOOTH);
        glCullFace(GL_BACK);
 }
 
@@ -528,7 +527,6 @@ static void draw_textured_end(void)
                GPU_set_tpage(NULL, 0, 0);
        }
 
-       glShadeModel(GL_FLAT);
        glDisable(GL_CULL_FACE);
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
index 848772600baa83a3ee965c19ab344db3dfb26e16..5d1c0bfa72e11941bcabbd52f21da4a7b1f86010 100644 (file)
@@ -1592,12 +1592,9 @@ static void draw_bundle_sphere(void)
 
                displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
-
                qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
-               glShadeModel(GL_SMOOTH);
                gluSphere(qobj, 0.05, 8, 8);
-               glShadeModel(GL_FLAT);
                gluDeleteQuadric(qobj);
 
                glEndList();
@@ -1779,8 +1776,6 @@ static void draw_viewport_reconstruction(
        GPU_basic_shader_colors(NULL, NULL, 0, 1.0f);
        GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
 
-       glShadeModel(GL_SMOOTH);
-
        tracking_object = tracking->objects.first;
        while (tracking_object) {
                draw_viewport_object_reconstruction(
@@ -1791,7 +1786,6 @@ static void draw_viewport_reconstruction(
        }
 
        /* restore */
-       glShadeModel(GL_FLAT);
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
@@ -2351,7 +2345,6 @@ static void drawlattice(View3D *v3d, Object *ob)
                
                if (ob->defbase.first && lt->dvert) {
                        actdef_wcol = ob->actdef;
-                       glShadeModel(GL_SMOOTH);
                }
        }
 
@@ -2380,10 +2373,6 @@ static void drawlattice(View3D *v3d, Object *ob)
                }
        }
        glEnd();
-       
-       /* restoration for weight colors */
-       if (actdef_wcol)
-               glShadeModel(GL_FLAT);
 
        if (is_edit) {
                BPoint *actbp = BKE_lattice_active_point_get(lt);
@@ -3248,17 +3237,15 @@ static void draw_em_fancy_edges(BMEditMesh *em, Scene *scene, View3D *v3d,
                            ((ts->selectmode & SCE_SELECT_VERTEX) || (me->drawflag & ME_DRAWEIGHT)))
                        {
                                if (draw_dm_edges_weight_check(me, v3d)) {
-                                       glShadeModel(GL_SMOOTH);
+                                       // Interpolate vertex weights
                                        draw_dm_edges_weight_interp(em, cageDM, ts->weightuser);
-                                       glShadeModel(GL_FLAT);
                                }
                                else if (ts->selectmode == SCE_SELECT_FACE) {
                                        draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act);
                                }
                                else {
-                                       glShadeModel(GL_SMOOTH);
+                                       // Interpolate vertex selection
                                        draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol);
-                                       glShadeModel(GL_FLAT);
                                }
                        }
                        else {
@@ -4461,10 +4448,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
 
        glEnableClientState(GL_VERTEX_ARRAY);
 
-       if (ob->type == OB_MBALL) {  /* mball always smooth shaded */
-               glShadeModel(GL_SMOOTH);
-       }
-
        /* track current material, -1 for none (needed for lines) */
        short col = -1;
        
@@ -4486,7 +4469,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
 
                                        // glVertexPointer(3, GL_FLOAT, 0, dl->verts);
                                        // glDrawArrays(GL_LINE_STRIP, 0, dl->nr);
-
                                        glBegin(GL_LINE_STRIP);
                                        for (int nr = dl->nr; nr; nr--, data += 3)
                                                glVertex3fv(data);
@@ -4517,15 +4499,15 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
                                                GPU_object_material_bind(dl->col + 1, use_glsl ? &gattribs : NULL);
                                                col = dl->col;
                                        }
-
-                                       if (dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
-                                       else glShadeModel(GL_FLAT);
+                                       /* FLAT/SMOOTH shading for surfaces */
+                                       glShadeModel((dl->rt & CU_SMOOTH) ? GL_SMOOTH : GL_FLAT);
 
                                        glEnableClientState(GL_NORMAL_ARRAY);
                                        glVertexPointer(3, GL_FLOAT, 0, dl->verts);
                                        glNormalPointer(GL_FLOAT, 0, dl->nors);
                                        glDrawElements(GL_QUADS, 4 * dl->totindex, GL_UNSIGNED_INT, dl->index);
                                        glDisableClientState(GL_NORMAL_ARRAY);
+                                       glShadeModel(GL_SMOOTH);
                                }
                                break;
 
@@ -4570,7 +4552,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
        }
 
        glDisableClientState(GL_VERTEX_ARRAY);
-       glShadeModel(GL_FLAT);
        glFrontFace(GL_CCW);
 
        if (col != -1) {
index 445a4cbdfd65aaa57b9d8d66c5a6c2eaa389da2c..bdc2234e2466e36512ba60744729c9b6a09b2a5e 100644 (file)
@@ -657,7 +657,6 @@ static void draw_rotation_guide(RegionView3D *rv3d)
 
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       glShadeModel(GL_SMOOTH);
        glPointSize(5);
        glEnable(GL_POINT_SMOOTH);
        glDepthMask(0);  /* don't overwrite zbuf */
@@ -2999,18 +2998,16 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
                                glLoadIdentity();
                                glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
                        }
-
+                       // Draw world
                        glEnable(GL_DEPTH_TEST);
                        glDepthFunc(GL_ALWAYS);
-                       glShadeModel(GL_SMOOTH);
                        glBegin(GL_TRIANGLE_STRIP);
                        glVertex3f(-1.0, -1.0, 1.0);
                        glVertex3f(1.0, -1.0, 1.0);
                        glVertex3f(-1.0, 1.0, 1.0);
                        glVertex3f(1.0, 1.0, 1.0);
                        glEnd();
-                       glShadeModel(GL_FLAT);
-
+                       //
                        if (material_not_bound) {
                                glMatrixMode(GL_PROJECTION);
                                glPopMatrix();
@@ -3048,8 +3045,6 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
                        glPushMatrix();
                        glLoadIdentity();
 
-                       glShadeModel(GL_SMOOTH);
-
                        /* calculate buffers the first time only */
                        if (!buf_calculated) {
                                for (x = 0; x < VIEWGRAD_RES_X; x++) {
@@ -3135,8 +3130,6 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
                        glMatrixMode(GL_MODELVIEW);
                        glPopMatrix();
 
-                       glShadeModel(GL_FLAT);
-
 #undef VIEWGRAD_RES_X
 #undef VIEWGRAD_RES_Y
                }
@@ -3160,7 +3153,6 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
 
                        glEnable(GL_DEPTH_TEST);
                        glDepthFunc(GL_ALWAYS);
-                       glShadeModel(GL_SMOOTH);
                        glBegin(GL_QUADS);
                        UI_ThemeColor(TH_LOW_GRAD);
                        glVertex3f(-1.0, -1.0, 1.0);
@@ -3169,8 +3161,6 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
                        glVertex3f(1.0, 1.0, 1.0);
                        glVertex3f(-1.0, 1.0, 1.0);
                        glEnd();
-                       glShadeModel(GL_FLAT);
-
                        glDepthFunc(GL_LEQUAL);
                        glDisable(GL_DEPTH_TEST);
 
index baa471e920b48575c0d53729f96145e322a14123..94d69a0169fe20728bb42a25705f1fb5e414ca09 100644 (file)
@@ -279,8 +279,6 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
 
                        col[3] = 0.5f; /* hard coded alpha, not that nice */
                        
-                       glShadeModel(GL_SMOOTH);
-                       
                        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
                                tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
                                
@@ -344,8 +342,6 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
                        BLI_buffer_free(&av_buf);
                        BLI_buffer_free(&auv_buf);
 
-                       glShadeModel(GL_FLAT);
-
                        break;
                }
        }
@@ -794,8 +790,7 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
                                UI_GetThemeColor4ubv(TH_EDGE_SELECT, col1);
 
                                if (interpedges) {
-                                       glShadeModel(GL_SMOOTH);
-
+                                       GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
                                        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
                                                if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
                                                        continue;
@@ -810,8 +805,6 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
                                                }
                                                glEnd();
                                        }
-
-                                       glShadeModel(GL_FLAT);
                                }
                                else {
                                        BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
index 8e38ac8876fa4d488c674e83419586c709e7fa89..6c78aec2ec78da4883035793084a2ebbaa409516 100644 (file)
@@ -51,7 +51,8 @@ typedef enum GPUBasicShaderOption {
        GPU_SHADER_SOLID_LIGHTING =   (1 << 5),   /* use faster lighting (set automatically) */
        GPU_SHADER_STIPPLE =          (1 << 6),   /* use stipple */
        GPU_SHADER_LINE =             (1 << 7),   /* draw lines */
-       GPU_SHADER_OPTIONS_NUM = 8,
+       GPU_SHADER_FLAT_NORMAL =      (1 << 8),   /* use flat normals */
+       GPU_SHADER_OPTIONS_NUM = 9,
        GPU_SHADER_OPTION_COMBINATIONS = (1 << GPU_SHADER_OPTIONS_NUM)
 } GPUBasicShaderOption;
 
index 4be50a078b7f3b4c23a57fa4df33165ae2b29789..c5a2d07bdc8c8b7d57f2ff7cc924117aaf36c32a 100644 (file)
@@ -376,6 +376,8 @@ static GPUShader *gpu_basic_shader(int options)
                        strcat(defines, "#define DRAW_LINE\n");
                        geom_glsl = datatoc_gpu_shader_basic_geom_glsl;
                }
+               if (options & GPU_SHADER_FLAT_NORMAL)
+                       strcat(defines, "#define USE_FLAT_NORMAL\n");
                if (options & GPU_SHADER_SOLID_LIGHTING)
                        strcat(defines, "#define USE_SOLID_LIGHTING\n");
                else if (options & GPU_SHADER_LIGHTING)
@@ -507,6 +509,12 @@ void GPU_basic_shader_bind(int options)
                                glDisable(GL_POLYGON_STIPPLE);
                }
 
+               if (options & GPU_SHADER_FLAT_NORMAL) {
+                       glShadeModel(GL_FLAT);
+               }
+               else {
+                       glShadeModel(GL_SMOOTH);
+               }
        }
 
        GPU_MATERIAL_STATE.bound_options = options;
index e8605e27595682590ff5924c79ef18a5eaae73ec..35bfc687052bb9a6095d4fc8f5b4795a78ab7461 100644 (file)
@@ -1863,10 +1863,14 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
                        GPU_buffer_bind(buffers->index_buf, GPU_BINDING_INDEX);
                }
 
-               if (wireframe)
+               if (wireframe) {
                        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-               else
-                       glShadeModel((buffers->smooth || buffers->face_indices_len) ? GL_SMOOTH : GL_FLAT);
+               }
+               else {
+                       bound_options = GPU_basic_shader_bound_options();
+                       GPU_basic_shader_bind(bound_options | ((buffers->smooth || buffers->face_indices_len) ?
+                                             0 : GPU_SHADER_FLAT_NORMAL));
+               }
 
                if (buffers->tot_quad) {
                        const char *offset = base;
index b6f977d12ab83c1b2ea1f5db752507a2f0a5249a..f998dc9904e0361967e12dca7b560f9ebb2703fd 100644 (file)
@@ -1995,8 +1995,9 @@ int GPU_object_material_bind(int nr, void *attribs)
                }
                else {
                        /* or do fixed function opengl material */
-                       GPU_basic_shader_colors(GMS.matbuf[nr].diff,
-                               GMS.matbuf[nr].spec, GMS.matbuf[nr].hard, GMS.matbuf[nr].alpha);
+                       GPU_basic_shader_colors(
+                               GMS.matbuf[nr].diff,
+                               GMS.matbuf[nr].spec, GMS.matbuf[nr].hard, GMS.matbuf[nr].alpha);
 
                        if (GMS.two_sided_lighting)
                                GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_TWO_SIDED);
@@ -2290,8 +2291,6 @@ void GPU_state_init(void)
        /* scaling matrices */
        glEnable(GL_NORMALIZE);
 
-       glShadeModel(GL_FLAT);
-
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_BLEND);
        glDisable(GL_DEPTH_TEST);
index ea5f6aef005ca229aa4dfb82513b18b2c20e90d8..01a335af0486d8ceb01897055bad0e63dac3be54 100644 (file)
 #define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP        11
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+#if defined(USE_FLAT_NORMAL)
+varying vec3 eyespace_vert_pos;
+#else
 varying vec3 varying_normal;
-
+#endif
 #ifndef USE_SOLID_LIGHTING
 varying vec3 varying_position;
 #endif
@@ -146,7 +149,11 @@ void main()
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
        /* compute normal */
+#if defined(USE_FLAT_NORMAL)
+       vec3 N = normalize(cross(dFdx(eyespace_vert_pos), dFdy(eyespace_vert_pos)));
+#else
        vec3 N = normalize(varying_normal);
+#endif
 
 #ifdef USE_TWO_SIDED
        if (!gl_FrontFacing)
index cef28ea30262f212f26fe1819cad96d0c42d0857..42fbdadf1d1edf7dd0ce793d08a2c593ee049a74 100644 (file)
@@ -1,6 +1,10 @@
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+#if defined(USE_FLAT_NORMAL)
+varying vec3 eyespace_vert_pos;
+#else
 varying vec3 varying_normal;
+#endif
 
 #ifndef USE_SOLID_LIGHTING
 varying vec3 varying_position;
@@ -28,7 +32,13 @@ void main()
        vec4 co = gl_ModelViewMatrix * gl_Vertex;
 
 #if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
+#if !defined(USE_FLAT_NORMAL)
        varying_normal = normalize(gl_NormalMatrix * gl_Normal);
+#endif
+#if defined(USE_FLAT_NORMAL)
+       /* transform vertex into eyespace */
+       eyespace_vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
+#endif
 
 #ifndef USE_SOLID_LIGHTING
        varying_position = co.xyz;