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:
authorAlexander Romanov <a.romanov@blend4web.com>2016-05-16 11:13:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-06-09 22:38:17 +0300
commit6798809c7ec8388509f541a64359b3d107e6fd3f (patch)
treecab8d4b80cfca2974814af7598248edd6368b6e5
parentd733826708f9b562687b78424e5c0835cba8c3c9 (diff)
Flat shading for basic shader
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
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c1
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c20
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c8
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c3
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c1
-rw-r--r--source/blender/editors/interface/interface_draw.c13
-rw-r--r--source/blender/editors/interface/interface_icons.c6
-rw-r--r--source/blender/editors/interface/interface_panel.c6
-rw-r--r--source/blender/editors/interface/interface_widgets.c12
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c1
-rw-r--r--source/blender/editors/space_view3d/drawanimviz.c2
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c11
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c2
-rw-r--r--source/blender/editors/space_view3d/drawobject.c29
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c14
-rw-r--r--source/blender/editors/uvedit/uvedit_draw.c9
-rw-r--r--source/blender/gpu/GPU_basic_shader.h3
-rw-r--r--source/blender/gpu/intern/gpu_basic_shader.c8
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c10
-rw-r--r--source/blender/gpu/intern/gpu_draw.c7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_basic_frag.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_basic_vert.glsl10
22 files changed, 56 insertions, 129 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 0de0e4d7797..d590a35bb57 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 392a38773e7..267f7a65e00 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -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)
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 8df07c5f3f4..6b81c47765b 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -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++) {
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 88bc3fb9854..b0d19320230 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -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)
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 0329598d711..79a2c494239 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -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) */
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 8fbc545cb77..d78b41820b4 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -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);
}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 222b0366791..6dc60f1d70b 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -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);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 62b373c58c8..85e32144bcd 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -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 */
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 19e0b55374e..5098e701638 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -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)
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 9c2d115108d..f6afd7a16e7 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -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; }
diff --git a/source/blender/editors/space_view3d/drawanimviz.c b/source/blender/editors/space_view3d/drawanimviz.c
index 9872b05da63..cf738de0202 100644
--- a/source/blender/editors/space_view3d/drawanimviz.c
+++ b/source/blender/editors/space_view3d/drawanimviz.c
@@ -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);
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index 1306e832592..1d9a515a5f2 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -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 */
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index 883f06763de..d8364011036 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -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);
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 848772600ba..5d1c0bfa72e 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -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) {
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 445a4cbdfd6..bdc2234e246 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -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);
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index baa471e920b..94d69a0169f 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -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) {
diff --git a/source/blender/gpu/GPU_basic_shader.h b/source/blender/gpu/GPU_basic_shader.h
index 8e38ac8876f..6c78aec2ec7 100644
--- a/source/blender/gpu/GPU_basic_shader.h
+++ b/source/blender/gpu/GPU_basic_shader.h
@@ -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;
diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c
index 4be50a078b7..c5a2d07bdc8 100644
--- a/source/blender/gpu/intern/gpu_basic_shader.c
+++ b/source/blender/gpu/intern/gpu_basic_shader.c
@@ -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;
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index e8605e27595..35bfc687052 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -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;
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index b6f977d12ab..f998dc9904e 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -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);
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
index ea5f6aef005..01a335af048 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
@@ -28,8 +28,11 @@
#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)
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
index cef28ea3026..42fbdadf1d1 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
@@ -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;