diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2015-11-27 23:32:14 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2015-12-06 21:35:15 +0300 |
commit | 147f7a1e860587a928f465b0b4d0ecf816c997be (patch) | |
tree | f391edb612d8a53a5b31ecfb3fd2a91c3d9683b2 /source/blender/editors | |
parent | 42bff8bb1ef759caaf0c6c419349cbf4cc866e9a (diff) |
OpenGL: isolate fixed function lighting in simple shader code.
Differential Revision: https://developer.blender.org/D1645
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 17 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawmesh.c | 132 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 129 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 3 |
4 files changed, 97 insertions, 184 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 97af45f6370..244aef633c1 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1219,26 +1219,22 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect) { static GLuint displist = 0; - float diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + float diffuse[3] = {1.0f, 1.0f, 1.0f}; float size; - /* store stuff */ - glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); - /* backdrop */ glColor3ubv((unsigned char *)wcol->inner); UI_draw_roundbox_corner_set(UI_CNR_ALL); UI_draw_roundbox_gl_mode(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); /* sphere color */ - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); /* setup lights */ GPULightData light = {0}; light.type = GPU_LIGHT_SUN; - copy_v3_v3(light.diffuse, diffn); + copy_v3_v3(light.diffuse, diffuse); zero_v3(light.specular); ui_but_v3_get(but, light.direction); @@ -1246,8 +1242,10 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect) for (int a = 1; a < 8; a++) GPU_simple_shader_light_set(a, NULL); - glEnable(GL_LIGHTING); - + /* setup shader */ + GPU_simple_shader_colors(diffuse, NULL, 0, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING); + /* transform to button */ glPushMatrix(); glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f); @@ -1278,10 +1276,9 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect) glCallList(displist); /* restore */ + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); GPU_default_lights(); - glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); /* AA circle */ glEnable(GL_BLEND); diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index cfffeb01b06..452e36e6eb5 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -63,6 +63,7 @@ #include "GPU_extensions.h" #include "GPU_draw.h" #include "GPU_material.h" +#include "GPU_simple_shader.h" #include "RE_engine.h" @@ -179,7 +180,6 @@ void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, bool d data.edge_flags = get_tface_mesh_marked_edge_info(me, draw_select_edges); glEnable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); ED_view3d_polygon_offset(rv3d, 1.0); /* Draw (Hidden) Edges */ @@ -231,10 +231,11 @@ static struct TextureDrawState { int is_lit, is_tex; int color_profile; bool use_backface_culling; + bool two_sided_lighting; unsigned char obcol[4]; bool is_texpaint; bool texpaint_material; /* use material slots for texture painting */ -} Gtexdraw = {NULL, NULL, NULL, false, 0, 0, 0, false, {0, 0, 0, 0}, false, false}; +} Gtexdraw = {NULL, NULL, NULL, false, 0, 0, 0, false, false, {0, 0, 0, 0}, false, false}; static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material *ma, struct TextureDrawState gtexdraw) { @@ -370,24 +371,26 @@ static bool set_draw_settings_cached(int clearcache, MTexPoly *texface, Material if (c_badtex) lit = 0; if (lit != c_lit || ma != c_ma) { if (lit) { - float spec[4]; - if (!ma) ma = give_current_material_or_def(NULL, 0); /* default material */ - - spec[0] = ma->spec * ma->specr; - spec[1] = ma->spec * ma->specg; - spec[2] = ma->spec * ma->specb; - spec[3] = 1.0; - - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(ma->har, 0, 128)); - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); + int options = GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR; + + if (gtexdraw.two_sided_lighting) + options |= GPU_SHADER_TWO_SIDED; + if (c_textured && !c_badtex) + options |= GPU_SHADER_TEXTURE_2D; + + if (!ma) + ma = give_current_material_or_def(NULL, 0); /* default material */ + + float specular[3]; + mul_v3_v3fl(specular, &ma->specr, ma->spec); + + GPU_simple_shader_colors(NULL, specular, ma->har, 0.0f); + GPU_simple_shader_bind(options); } else { - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); } + c_lit = lit; c_ma = ma; } @@ -488,12 +491,12 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene); Gtexdraw.use_game_mat = (RE_engines_find(scene->r.engine)->flag & RE_GAME) != 0; Gtexdraw.use_backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; + Gtexdraw.two_sided_lighting = (me->flag & ME_TWOSIDED); memcpy(Gtexdraw.obcol, obcol, sizeof(obcol)); set_draw_settings_cached(1, NULL, NULL, Gtexdraw); glShadeModel(GL_SMOOTH); glCullFace(GL_BACK); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); } static void draw_textured_end(void) @@ -526,7 +529,7 @@ static void draw_textured_end(void) glShadeModel(GL_FLAT); glDisable(GL_CULL_FACE); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); /* XXX, bad patch - GPU_default_lights() calls * glLightfv(GL_POSITION, ...) which @@ -1016,6 +1019,8 @@ typedef struct TexMatCallback { Object *ob; Mesh *me; DerivedMesh *dm; + bool shadeless; + bool two_sided_lighting; } TexMatCallback; static void tex_mat_set_material_cb(void *UNUSED(userData), int mat_nr, void *attribs) @@ -1035,31 +1040,21 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) Image *ima; ImageUser *iuser; bNode *node; - int texture_set = 0; /* draw image texture if we find one */ if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node, NULL)) { /* get openl texture */ int mipmap = 1; int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap, false) : 0; - float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (bindcode) { NodeTexBase *texbase = node->storage; /* disable existing material */ GPU_object_material_unbind(); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero); - glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0); /* bind texture */ - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, ima->bindcode); - glColor3f(1.0f, 1.0f, 1.0f); glMatrixMode(GL_TEXTURE); glLoadMatrixf(texbase->tex_mapping.mat); @@ -1073,20 +1068,35 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs) gattribs->layer[0].gltexco = 1; gattribs->totlayer = 1; - texture_set = 1; + /* bind material */ + float diffuse[3] = {1.0f, 1.0f, 1.0f}; + + int options = GPU_SHADER_TEXTURE_2D; + if (!data->shadeless) + options |= GPU_SHADER_LIGHTING; + if (data->two_sided_lighting) + options |= GPU_SHADER_TWO_SIDED; + + GPU_simple_shader_colors(diffuse, NULL, 0, 0.0f); + GPU_simple_shader_bind(options); + + return; } } - if (!texture_set) { + /* disable texture material */ + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); + + if (data->shadeless) { + glColor3f(1.0f, 1.0f, 1.0f); + memset(gattribs, 0, sizeof(*gattribs)); + } + else { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); - /* disable texture */ - glDisable(GL_TEXTURE_2D); - glDisable(GL_COLOR_MATERIAL); - - /* draw single color */ + /* enable solid material */ GPU_object_material_bind(mat_nr, attribs); } } @@ -1140,17 +1150,11 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Mesh *me = ob->data; - if ((v3d->flag2 & V3D_SHADELESS_TEX) && - ((v3d->drawtype == OB_TEXTURE) || (ob->mode & OB_MODE_TEXTURE_PAINT))) - { - glColor3f(1.0f, 1.0f, 1.0f); - } - else { - glEnable(GL_LIGHTING); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); - } + bool shadeless = ((v3d->flag2 & V3D_SHADELESS_TEX) && + ((v3d->drawtype == OB_TEXTURE) || (ob->mode & OB_MODE_TEXTURE_PAINT))); + bool two_sided_lighting = (me->flag & ME_TWOSIDED) != 0; - TexMatCallback data = {scene, ob, me, dm}; + TexMatCallback data = {scene, ob, me, dm, shadeless, two_sided_lighting}; bool (*set_face_cb)(void *, int); bool picking = (G.f & G_PICKSEL) != 0; @@ -1174,13 +1178,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, set_face_cb, &data); } else { - float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - /* draw textured */ - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, zero); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero); - glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0); - dm->drawMappedFacesMat(dm, tex_mat_set_texture_cb, set_face_cb, &data); @@ -1189,11 +1187,11 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, GPU_end_object_materials(); /* reset opengl state */ - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_TEXTURE_2D); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - glDisable(GL_LIGHTING); + GPU_end_object_materials(); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); + glBindTexture(GL_TEXTURE_2D, 0); + glFrontFace(GL_CCW); glMatrixMode(GL_TEXTURE); @@ -1210,25 +1208,15 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, /* Vertex Paint and Weight Paint */ static void draw_mesh_paint_light_begin(void) { - const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; - - GPU_object_material_bind(0, NULL); - - /* but set default spec */ - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); - - /* diffuse */ - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); + /* get material diffuse color from vertex colors but set default spec */ + const float specular[3] = {0.47f, 0.47f, 0.47f}; + GPU_simple_shader_colors(NULL, specular, 35, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR); } + static void draw_mesh_paint_light_end(void) { - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); - - GPU_object_material_unbind(); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); } void draw_mesh_paint_weight_faces(DerivedMesh *dm, const bool use_light, diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 53b14eb75b2..af44c8ca998 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -89,6 +89,7 @@ #include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_select.h" +#include "GPU_simple_shader.h" #include "ED_mesh.h" #include "ED_particle.h" @@ -1692,8 +1693,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D v3d->bundle_size / 0.05f / camera_size[2]); if (v3d->drawtype == OB_WIRE) { - glDisable(GL_LIGHTING); - if ((dflag & DRAW_CONSTCOLOR) == 0) { if (selected && (track->flag & TRACK_CUSTOMCOLOR) == 0) { glColor3ubv(ob_wire_col); @@ -1704,8 +1703,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D } drawaxes(0.05f, v3d->bundle_drawtype); - - glEnable(GL_LIGHTING); } else if (v3d->drawtype > OB_WIRE) { if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) { @@ -1716,13 +1713,11 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D } glLineWidth(2.0f); - glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); draw_bundle_sphere(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glEnable(GL_LIGHTING); glLineWidth(1.0f); } @@ -1734,8 +1729,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D draw_bundle_sphere(); } else { - glDisable(GL_LIGHTING); - if ((dflag & DRAW_CONSTCOLOR) == 0) { if (selected) { glColor3ubv(ob_wire_col); @@ -1747,8 +1740,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D } drawaxes(0.05f, v3d->bundle_drawtype); - - glEnable(GL_LIGHTING); } } @@ -1776,7 +1767,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D MovieReconstructedCamera *camera = reconstruction->cameras; int a = 0; - glDisable(GL_LIGHTING); UI_ThemeColor(TH_CAMERA_PATH); glLineWidth(2.0f); @@ -1787,7 +1777,6 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D glEnd(); glLineWidth(1.0f); - glEnable(GL_LIGHTING); } } } @@ -1811,9 +1800,9 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, if (v3d->flag2 & V3D_RENDER_OVERRIDE) return; - glEnable(GL_LIGHTING); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_COLOR_MATERIAL); + GPU_simple_shader_colors(NULL, NULL, 0, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR); + glShadeModel(GL_SMOOTH); tracking_object = tracking->objects.first; @@ -1826,8 +1815,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, /* restore */ glShadeModel(GL_FLAT); - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); if ((dflag & DRAW_CONSTCOLOR) == 0) { glColor3ubv(ob_wire_col); @@ -2135,7 +2123,6 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base BKE_camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale, asp, shift, &drawsize, vec); - glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); /* camera frame */ @@ -3815,17 +3802,12 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d, } } else { - /* 3 floats for position, - * 3 for normal and times two because the faces may actually be quads instead of triangles */ - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); - - glEnable(GL_LIGHTING); glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_object_material_bind, NULL, me->edit_btmesh, DM_DRAW_SKIP_HIDDEN | DM_DRAW_NEED_NORMALS); glFrontFace(GL_CCW); - glDisable(GL_LIGHTING); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + + GPU_object_material_unbind(); } /* Setup for drawing wire over, disable zbuffer @@ -4004,13 +3986,13 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm) glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f); glDepthMask(0); - /* if transparent, we cannot draw the edges for solid select... edges have no material info. - * drawFacesSolid() doesn't draw the transparent faces */ + /* if transparent, we cannot draw the edges for solid select... edges + * have no material info. GPU_object_material_visible will skip the + * transparent faces */ if (ob->dtx & OB_DRAWTRANSP) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind); + dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_visible); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - GPU_object_material_unbind(); } else { dm->drawEdges(dm, 0, 1); @@ -4156,9 +4138,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D /* for object selection draws no shade */ if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) { dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind); + GPU_object_material_unbind(); } else { - const float spec[4] = {0.47f, 0.47f, 0.47f, 0.47f}; + const float specular[3] = {0.47f, 0.47f, 0.47f}; /* draw outline */ if ((v3d->flag & V3D_SELECT_OUTLINE) && @@ -4173,21 +4156,13 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D /* materials arent compatible with vertex colors */ GPU_end_object_materials(); - GPU_object_material_bind(0, NULL); - - /* set default spec */ - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); - /* diffuse */ - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); + /* set default specular */ + GPU_simple_shader_colors(NULL, specular, 35, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR); dm->drawMappedFaces(dm, NULL, NULL, NULL, NULL, DM_DRAW_USE_COLORS | DM_DRAW_NEED_NORMALS); - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); - GPU_object_material_unbind(); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); } } else { @@ -4202,9 +4177,6 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D draw_mesh_object_outline(v3d, ob, dm); } - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); - - glEnable(GL_LIGHTING); glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); if (ob->sculpt && (p = BKE_paint_get_active(scene))) { @@ -4225,12 +4197,9 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D else dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind); - GPU_object_material_unbind(); - glFrontFace(GL_CCW); - glDisable(GL_LIGHTING); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); + GPU_object_material_unbind(); if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { if ((dflag & DRAW_CONSTCOLOR) == 0) { @@ -4534,7 +4503,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag, if (lb == NULL) return; - glEnable(GL_LIGHTING); glEnableClientState(GL_VERTEX_ARRAY); if (ob->type == OB_MBALL) { /* mball always smooth shaded */ @@ -4551,8 +4519,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag, if (ob->type == OB_SURF) { int nr; - glDisable(GL_LIGHTING); - if ((dflag & DRAW_CONSTCOLOR) == 0) glColor3ubv(ob_wire_col); @@ -4563,16 +4529,12 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag, for (nr = dl->nr; nr; nr--, data += 3) glVertex3fv(data); glEnd(); - - glEnable(GL_LIGHTING); } break; case DL_POLY: if (ob->type == OB_SURF) { int nr; - glDisable(GL_LIGHTING); - /* for some reason glDrawArrays crashes here in half of the platforms (not osx) */ //glVertexPointer(3, GL_FLOAT, 0, dl->verts); //glDrawArrays(GL_LINE_LOOP, 0, dl->nr); @@ -4581,8 +4543,6 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag, for (nr = dl->nr; nr; nr--, data += 3) glVertex3fv(data); glEnd(); - - glEnable(GL_LIGHTING); } break; case DL_SURF: @@ -4637,8 +4597,9 @@ static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag, glDisableClientState(GL_VERTEX_ARRAY); glShadeModel(GL_FLAT); - glDisable(GL_LIGHTING); glFrontFace(GL_CCW); + + GPU_object_material_unbind(); } static void drawCurveDMWired(Object *ob) @@ -4665,11 +4626,8 @@ static bool drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, int glsl = draw_glsl_material(scene, ob, v3d, dt); GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL); - if (!glsl) { - glEnable(GL_LIGHTING); + if (!glsl) dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind); - glDisable(GL_LIGHTING); - } else dm->drawFacesGLSL(dm, GPU_object_material_bind); @@ -5503,19 +5461,10 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv glEnableClientState(GL_COLOR_ARRAY); } - glEnable(GL_LIGHTING); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_COLOR_MATERIAL); - } -#if 0 - else { - glDisableClientState(GL_NORMAL_ARRAY); - - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_LIGHTING); - UI_ThemeColor(TH_WIRE); + // XXX test + GPU_simple_shader_colors(NULL, NULL, 0.0f, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR); } -#endif if (totchild && (part->draw & PART_DRAW_PARENT) == 0) totpart = 0; @@ -5546,8 +5495,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if (part->draw & PART_DRAW_GUIDE_HAIRS) { DerivedMesh *hair_dm = psys->hair_out_dm; - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -5591,8 +5538,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv glEnd(); } - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); glEnableClientState(GL_NORMAL_ARRAY); if ((dflag & DRAW_CONSTCOLOR) == 0) if (part->draw_col == PART_DRAW_COL_MAT) @@ -5607,8 +5552,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv int *res = clmd->hair_grid_res; int i; - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -5663,8 +5606,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv glEnd(); glDisable(GL_BLEND); - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); glEnableClientState(GL_NORMAL_ARRAY); if ((dflag & DRAW_CONSTCOLOR) == 0) if (part->draw_col == PART_DRAW_COL_MAT) @@ -5695,7 +5636,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if (1) { //ob_dt > OB_WIRE) { if (part->draw_col == PART_DRAW_COL_MAT) glDisableClientState(GL_COLOR_ARRAY); - glDisable(GL_COLOR_MATERIAL); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); } if (cdata2) { @@ -5756,11 +5697,8 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if (pdd->ndata && ob_dt > OB_WIRE) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, pdd->ndata); - glEnable(GL_LIGHTING); - } - else { - glDisableClientState(GL_NORMAL_ARRAY); - glDisable(GL_LIGHTING); + GPU_simple_shader_colors(NULL, NULL, 0.0f, 1.0f); + GPU_simple_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR); } if ((dflag & DRAW_CONSTCOLOR) == 0) { @@ -5792,7 +5730,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv /* 7. */ - glDisable(GL_LIGHTING); + GPU_simple_shader_bind(GPU_SHADER_USE_COLOR); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -5867,14 +5805,10 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); - if (pset->brushtype == PE_BRUSH_WEIGHT) { + if (pset->brushtype == PE_BRUSH_WEIGHT) glLineWidth(2.0f); - glDisable(GL_LIGHTING); - } cache = edit->pathcache; for (i = 0, point = edit->points; i < totpoint; i++, point++) { @@ -5987,8 +5921,6 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit) } glDisable(GL_BLEND); - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); @@ -8664,7 +8596,6 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *r } glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); - glEnable(GL_LIGHTING); if (dm) { dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind); @@ -8673,7 +8604,7 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *r else if (edm) edm->drawMappedFaces(edm, NULL, GPU_object_material_bind, NULL, NULL, DM_DRAW_NEED_NORMALS); - glDisable(GL_LIGHTING); + GPU_object_material_unbind(); } if (edm) edm->release(edm); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 9393092fffa..781c848285a 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -3309,9 +3309,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( float winmat[4][4]; if (own_ofs) { - /* state changes make normal drawing go weird otherwise */ - glPushAttrib(GL_LIGHTING_BIT); - /* bind */ ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out); if (ofs == NULL) { |