Flat shading for basic shader
authorAlexander Romanov <a.romanov@blend4web.com>
Mon, 16 May 2016 08:13:21 +0000 (11:13 +0300)
committerAlexander Romanov <a.romanov@blend4web.com>
Mon, 16 May 2016 08:13:21 +0000 (11:13 +0300)
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 57926e6a56aa33b99a79d9cee07f76c67591dc37..a32fd99aa045b2d0010fd66d00d8e7bd8e9a6491 100644 (file)
@@ -3840,7 +3840,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 e6741657f47dd959940130cdd6297d79e3a230a2..87dc08e51249d7f40ce7394a36c30057675866d1 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(
@@ -550,8 +546,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;
@@ -630,7 +625,6 @@ static void cdDM_drawFacesTex_common(
        }
 
        GPU_buffers_unbind();
-       glShadeModel(GL_FLAT);
        
 }
 
@@ -739,9 +733,6 @@ static void cdDM_drawMappedFaces(
                        }
                }
        }
-               
-
-       glShadeModel(GL_SMOOTH);
 
        tot_tri_elem = dm->drawObject->tot_triangle_point;
 
@@ -838,7 +829,6 @@ static void cdDM_drawMappedFaces(
        }
 
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-       glShadeModel(GL_FLAT);
 
        GPU_buffers_unbind();
 
@@ -926,8 +916,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");
@@ -1146,8 +1134,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)
@@ -1196,8 +1182,6 @@ static void cdDM_drawMappedFacesMat(
 
        matnr = -1;
 
-       glShadeModel(GL_SMOOTH);
-
        memset(&attribs, 0, sizeof(attribs));
 
        glBegin(GL_TRIANGLES);
@@ -1253,8 +1237,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 6c1174476640d9c13dbf653b5f14a299c498b88b..e57e9ffcd66d0de181b5b1f5928b94ae1459178e 100644 (file)
@@ -1235,8 +1235,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 */
@@ -1383,8 +1381,6 @@ static void emDM_drawFacesTex_common(
                        }
                }
        }
-
-       glShadeModel(GL_FLAT);
 }
 
 static void emDM_drawFacesTex(
@@ -1505,8 +1501,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++) {
@@ -1616,8 +1610,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 a84b83524172d68daaad807915f4fe0f2bdec6fb..a8e8f10962d9ef2f0af79f35b694c47099b99828 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;
@@ -3160,7 +3159,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 b5d9283f6c67227c0b75f600f5c2497c9d233c0f..43c82732451cc4e056f0f7be5f4efc7586a7ebab 100644 (file)
@@ -609,6 +609,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 34ea849aea78ff7b7e5bca7fc4798f183a62fefe..b39ddad5140b4ebb8fc2329402b7a695376ad19e 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 d1461f1acecd66c6fee3d127e717b343c3596c1b..7d74ad14b61c13124648089b82f95044f7faa75b 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);
                }
        }
        
@@ -2304,8 +2301,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);
@@ -2323,8 +2318,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);
@@ -2356,7 +2349,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:
@@ -2479,8 +2471,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 c6b2ccee85be88621d48399c4989b45e2c1ec142..9917486d5497348d334304882ec9f16dedf5e488 100644 (file)
@@ -430,10 +430,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();
@@ -889,7 +888,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); 
@@ -967,7 +965,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);
        }
        
@@ -1687,7 +1684,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);
                        
@@ -1710,7 +1706,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);
                }
        }
        
@@ -2132,7 +2127,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);
 
@@ -2147,7 +2141,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 345e47940d585b7e41e9b988c7e305bca7b62dde..53d4ac088e58cd0a74c9e7389c331c814471b9f6 100644 (file)
@@ -495,7 +495,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);
 }
 
@@ -527,7 +526,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 c5d4d8ecf7d7a0bd68c5e6d9c2a21ad84efe330f..cdee56dd6d84989f534565e248b5953d717a1688 100644 (file)
@@ -1581,12 +1581,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();
@@ -1767,8 +1764,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(
@@ -1779,7 +1774,6 @@ static void draw_viewport_reconstruction(
        }
 
        /* restore */
-       glShadeModel(GL_FLAT);
        GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
        if ((dflag & DRAW_CONSTCOLOR) == 0) {
@@ -2339,7 +2333,6 @@ static void drawlattice(View3D *v3d, Object *ob)
                
                if (ob->defbase.first && lt->dvert) {
                        actdef_wcol = ob->actdef;
-                       glShadeModel(GL_SMOOTH);
                }
        }
 
@@ -2368,10 +2361,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);
@@ -3236,17 +3225,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 {
@@ -4444,10 +4431,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;
        
@@ -4469,7 +4452,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);
@@ -4500,7 +4482,7 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
                                                GPU_object_material_bind(dl->col + 1, use_glsl ? &gattribs : NULL);
                                                col = dl->col;
                                        }
-
+                                       // FLAT/SMOOTH shading for surfaces
                                        if (dl->rt & CU_SMOOTH) glShadeModel(GL_SMOOTH);
                                        else glShadeModel(GL_FLAT);
 
@@ -4509,6 +4491,7 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
                                        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;
 
@@ -4553,7 +4536,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 1c51248a86e45ee3da519f6abeec981e5824c060..027d90ef0399047533aaa072691a95df563bb7ef 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 */
@@ -2993,18 +2992,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();
@@ -3042,8 +3039,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++) {
@@ -3129,8 +3124,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
                }
@@ -3154,7 +3147,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);
@@ -3163,8 +3155,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 df2da9718456fa30ddb0b44fe425755c00067183..b9335ca60b6a0885afe3450251ef9d6191bc5aa4 100644 (file)
@@ -50,7 +50,8 @@ typedef enum GPUBasicShaderOption {
        GPU_SHADER_SOLID_LIGHTING =   (1 << 4),   /* use faster lighting (set automatically) */
        GPU_SHADER_STIPPLE =          (1 << 5),   /* use stipple */
        GPU_SHADER_LINE =             (1 << 6),   /* draw lines */
-       GPU_SHADER_OPTIONS_NUM = 7,
+       GPU_SHADER_FLAT_NORMAL =      (1 << 7),   /* use flat normals */
+       GPU_SHADER_OPTIONS_NUM = 8,
        GPU_SHADER_OPTION_COMBINATIONS = (1 << GPU_SHADER_OPTIONS_NUM)
 } GPUBasicShaderOption;
 
index b6fe40a13ee967177aca385f7b3e7e98dad8123d..f2871dcc9d6804fafe669cc5d87c67224f1f849e 100644 (file)
@@ -355,6 +355,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)
@@ -455,6 +457,11 @@ 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 072ff5235bfc268c59b8f7f5433713044e981ab3..9c14cc704e18eaecb56f1100bc581874a2cc2c24 100644 (file)
@@ -1857,8 +1857,10 @@ void GPU_draw_pbvh_buffers(GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
 
                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 ebcd2e417beff04bc3a5048d2e765048f43462b6..f63d5cf860f1d96126430ae593228c7121f0a37b 100644 (file)
@@ -2207,8 +2207,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 c7b29ee5707c0c5433c7a7c4533810dd37cac11e..e30b68bbab5825f1e19ba53e3119e649759ff668 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
@@ -137,7 +140,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 04900001998f0f4461d4a7608ae3527f0dac24dc..e6af492998dd41b0bef999c2e45b32a22c2fcf5a 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;