Commit: 456d145d070e456bd3836f3529453043ce53a0b0
Author: Mike Erwin
Date:   Tue Oct 25 19:34:17 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB456d145d070e456bd3836f3529453043ce53a0b0

OpenGL: new mesh draw routines for new viewport

Totally WIP.

Started with copies of legacy routines, modified to use the new shaders & batch 
cache. Not all features are implemented; this is why we keep legacy viewport 
around during development!

===================================================================

M       source/blender/editors/space_view3d/drawobject.c

===================================================================

diff --git a/source/blender/editors/space_view3d/drawobject.c 
b/source/blender/editors/space_view3d/drawobject.c
index ba3dfb7..8df1007 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -974,7 +974,7 @@ void drawcircball(int mode, const float cent[3], float rad, 
const float tmat[4][
        glDisableClientState(GL_VERTEX_ARRAY);
 }
 
-void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], 
unsigned pos)
+static void imm_drawcircball(const float cent[3], float rad, const float 
tmat[4][4], unsigned pos)
 {
        float verts[CIRCLE_RESOL][3];
 
@@ -4225,9 +4225,15 @@ static void draw_em_fancy(Scene *scene, ARegion *ar, 
View3D *v3d,
 #endif
 }
 
+static void draw_em_fancy_new(Scene *scene, ARegion *ar, View3D *v3d,
+                              Object *ob, BMEditMesh *em, DerivedMesh *cageDM, 
DerivedMesh *finalDM, const char dt)
+{
+       /* for now... nothing! */
+}
+
 /* Mesh drawing routines */
 
-void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
+void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm) /* 
LEGACY */
 {
        if ((v3d->transp == false) &&  /* not when we draw the transparent pass 
*/
            (ob->mode & OB_MODE_ALL_PAINT) == false) /* not when painting (its 
distracting) - campbell */
@@ -4251,6 +4257,51 @@ void draw_mesh_object_outline(View3D *v3d, Object *ob, 
DerivedMesh *dm)
        }
 }
 
+static void draw_mesh_object_outline_new(View3D *v3d, RegionView3D *rv3d, 
Object *ob, DerivedMesh *dm)
+{
+       if ((v3d->transp == false) &&  /* not when we draw the transparent pass 
*/
+           (ob->mode & OB_MODE_ALL_PAINT) == false) /* not when painting (its 
distracting) - campbell */
+       {
+               glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
+               glDepthMask(GL_FALSE);
+
+               const float outline_color[4];
+               UI_GetThemeColor4fv(TH_SELECT, outline_color);
+#if 1
+               Batch *fancy_edges = MBC_get_fancy_edges(dm);
+
+               if (rv3d->persp == RV3D_ORTHO) {
+                       Batch_set_builtin_program(fancy_edges, 
GPU_SHADER_EDGES_FRONT_BACK_ORTHO);
+                       /* set eye vector, transformed to object coords */
+                       float eye[3] = { 0.0f, 0.0f, 1.0f }; /* looking into 
the screen */
+                       mul_m3_v3(gpuGetNormalMatrixInverse(NULL), eye);
+                       Batch_Uniform3fv(fancy_edges, "eye", eye);
+               }
+               else {
+                       Batch_set_builtin_program(fancy_edges, 
GPU_SHADER_EDGES_FRONT_BACK_PERSP);
+                       glEnable(GL_BLEND); /* hack until we support geometry 
shaders on Mac */
+               }
+
+               Batch_Uniform1b(fancy_edges, "drawFront", false);
+               Batch_Uniform1b(fancy_edges, "drawBack", false);
+               Batch_Uniform1b(fancy_edges, "drawSilhouette", true);
+               Batch_Uniform4fv(fancy_edges, "silhouetteColor", outline_color);
+
+               Batch_draw(fancy_edges);
+
+               if (rv3d->persp != RV3D_ORTHO) {
+                       glDisable(GL_BLEND); /* hack */
+               }
+#else
+               Batch *batch = MBC_get_all_edges(dm);
+               Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+               Batch_Uniform4fv(batch, "color", outline_color);
+               Batch_draw(batch);
+#endif
+               glDepthMask(GL_TRUE);
+       }
+}
+
 static bool object_is_halo(Scene *scene, Object *ob)
 {
        const Material *ma = give_current_material(ob, 1);
@@ -4629,6 +4680,412 @@ static bool draw_mesh_object(Scene *scene, ARegion *ar, 
View3D *v3d, RegionView3
        return retval;
 }
 
+static void draw_mesh_fancy_new(Scene *scene, ARegion *ar, View3D *v3d, 
RegionView3D *rv3d, Base *base,
+                                const char dt, const unsigned char 
ob_wire_col[4], const short dflag)
+{
+       if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
+               /* too complicated! use existing methods */
+               /* TODO: move this into a separate depth pre-pass */
+               draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, ob_wire_col, 
dflag);
+               return;
+       }
+
+#ifdef WITH_GAMEENGINE
+       Object *ob = (rv3d->rflag & RV3D_IS_GAME_ENGINE) ? 
BKE_object_lod_meshob_get(base->object, scene) : base->object;
+#else
+       Object *ob = base->object;
+#endif
+       Mesh *me = ob->data;
+       eWireDrawMode draw_wire = OBDRAW_WIRE_OFF; /* could be bool 
draw_wire_overlay */
+       bool no_edges, no_faces;
+       DerivedMesh *dm = mesh_get_derived_final(scene, ob, 
scene->customdata_mask);
+       const bool is_obact = (ob == OBACT);
+       int draw_flags = (is_obact && BKE_paint_select_face_test(ob)) ? 
DRAW_FACE_SELECT : 0;
+
+       if (!dm)
+               return;
+
+       const bool solid = dt >= OB_SOLID;
+       if (solid) {
+               DM_update_materials(dm, ob);
+       }
+
+       /* Check to draw dynamic paint colors (or weights from WeightVG 
modifiers).
+        * Note: Last "preview-active" modifier in stack will win! */
+       if (DM_get_loop_data_layer(dm, CD_PREVIEW_MLOOPCOL) && 
modifiers_isPreview(ob))
+               draw_flags |= DRAW_MODIFIERS_PREVIEW;
+
+       /* Unwanted combination */
+       if (draw_flags & DRAW_FACE_SELECT) {
+               draw_wire = OBDRAW_WIRE_OFF;
+       }
+       else if (ob->dtx & OB_DRAWWIRE) {
+               draw_wire = OBDRAW_WIRE_ON;
+       }
+
+       /* check polys instead of tessfaces because of dyntopo where tessfaces 
don't exist */
+       if (dm->type == DM_TYPE_CCGDM) {
+               no_edges = !subsurf_has_edges(dm);
+               no_faces = !subsurf_has_faces(dm);
+       }
+       else {
+               no_edges = (dm->getNumEdges(dm) == 0);
+               no_faces = (dm->getNumPolys(dm) == 0);
+       }
+
+       if (solid) {
+               /* vertexpaint, faceselect wants this, but it doesnt work for 
shaded? */
+               glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
+       }
+
+       if (dt == OB_BOUNDBOX) {
+               if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= 
OB_WIRE) == 0)
+                       draw_bounding_volume(ob, ob->boundtype);
+       }
+       else if ((no_faces && no_edges) ||
+                ((!is_obact || (ob->mode == OB_MODE_OBJECT)) && 
object_is_halo(scene, ob)))
+       {
+               glPointSize(1.5);
+               // dm->drawVerts(dm);
+               // TODO: draw smooth round points as a batch
+       }
+       else if ((dt == OB_WIRE) || no_faces) {
+               draw_wire = OBDRAW_WIRE_ON; /* draw wire only, no depth buffer 
stuff */
+
+               /* TODO: enable depth for wireframes */
+
+               glLineWidth(1.0f);
+
+               float color[4];
+               rgba_uchar_to_float(color, ob_wire_col);
+
+               /* TODO:
+                * const bool active = (ob == CTX_data_active_object(C));
+                * const int theme = active ? TH_ACTIVE : (base->flag & SELECT) 
? TH_SELECT : TH_WIRE;
+                * UI_GetThemeColor4fv(theme, color);
+                */
+
+#if 0
+               Batch *fancy_edges = MBC_get_fancy_edges(dm);
+
+               if (rv3d->persp == RV3D_ORTHO) {
+                       Batch_set_builtin_program(fancy_edges, 
GPU_SHADER_EDGES_FRONT_BACK_ORTHO);
+                       /* set eye vector, transformed to object coords */
+                       float eye[3] = { 0.0f, 0.0f, 1.0f }; /* looking into 
the screen */
+                       mul_m3_v3(gpuGetNormalMatrixInverse(NULL), eye);
+                       Batch_Uniform3fv(fancy_edges, "eye", eye);
+               }
+               else {
+                       Batch_set_builtin_program(fancy_edges, 
GPU_SHADER_EDGES_FRONT_BACK_PERSP);
+               }
+
+               /* TODO: nice variations (lighter & darker shades) of base 
color */
+               float backColor[4] = { 0.5f, 0.3f, 0.0f, 1.0f };
+               float outlineColor[4] = { 1.0f, 0.7f, 0.3f, 1.0f };
+
+               Batch_Uniform4fv(fancy_edges, "frontColor", color);
+               Batch_Uniform4fv(fancy_edges, "backColor", backColor);
+               Batch_Uniform1b(fancy_edges, "drawFront", true);
+               Batch_Uniform1b(fancy_edges, "drawBack", true);
+               Batch_Uniform1b(fancy_edges, "drawSilhouette", true);
+               Batch_Uniform4fv(fancy_edges, "silhouetteColor", outlineColor);
+
+               Batch_draw(fancy_edges);
+#else
+               Batch *batch = MBC_get_all_edges(dm);
+               Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+               Batch_Uniform4fv(batch, "color", color);
+               Batch_draw(batch);
+#endif
+       }
+       else if (((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
+                check_object_draw_texture(scene, v3d, dt))
+       {
+               bool draw_loose = true;
+
+               if ((v3d->flag & V3D_SELECT_OUTLINE) &&
+                   ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+                   (base->flag & SELECT) &&
+                   !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) &&
+                   (draw_wire == OBDRAW_WIRE_OFF))
+               {
+                       draw_mesh_object_outline_new(v3d, rv3d, ob, dm);
+               }
+
+               if (draw_glsl_material(scene, ob, v3d, dt) && !(draw_flags & 
DRAW_MODIFIERS_PREVIEW)) {
+                       Paint *p;
+
+                       glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : 
GL_CCW);
+
+                       if ((v3d->flag2 & V3D_SHOW_SOLID_MATCAP) && ob->sculpt 
&& (p = BKE_paint_get_active(scene))) {
+                               GPUVertexAttribs gattribs;
+                               float planes[4][4];
+                               float (*fpl)[4] = NULL;
+                               const bool fast = (p->flags & 
PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
+
+                               if (ob->sculpt->partial_redraw) {
+                                       if (ar->do_draw & RGN_DRAW_PARTIAL) {
+                                               
ED_sculpt_redraw_planes_get(planes, ar, rv3d, ob);
+                                               fpl = planes;
+                                               ob->sculpt->partial_redraw = 0;
+                                       }
+                               }
+
+                               GPU_object_material_bind(1, &gattribs);
+                               dm->drawFacesSolid(dm, fpl, fast, NULL);
+                               draw_loose = false;
+                       }
+                       else
+                               dm->drawFacesGLSL(dm, GPU_object_material_bind);
+
+                       GPU_object_material_unbind();
+
+                       glFrontFace(GL_CCW);
+
+                       if (draw_flags & DRAW_FACE_SELECT)
+                               draw_mesh_face_select(rv3d, me, dm, false);
+               }
+               else {
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, 
draw_flags);
+               }
+
+               if (draw_loose && !(draw_flags & DRAW_FACE_SELECT)) {
+                       if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       glColor3ubv(ob_wire_col);
+                               }
+                               glLineWidth(1.0f);
+                               dm->drawLooseEdges(dm);
+                       }
+               }
+       }
+       else if (dt == OB_SOLID) {
+               if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
+                       /* for object selection draws no shade */
+                       if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
+                               /* TODO: draw basic faces with 
GPU_SHADER_3D_DEPTH_ONLY */
+                       }
+                       else {
+                               const float specular[3] = {0.47f, 0.47f, 0.47f};
+
+                               /* draw outline */
+                               /* TODO: move this into a separate pass */
+                               if ((v3d->flag & V3D_SELECT_OUTLINE) &&
+                                   ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
+                                   (base->flag & SELECT) &&
+                                   (draw_wire == OBDRAW_WIRE_OFF) &&
+                                   (ob->sculpt == NULL))
+                               {
+                                       draw_mesh_object_outline_new(v3d, rv3d, 
ob, dm);
+                               }
+
+                               /* materials arent compatible with vertex 
colors */
+                               GPU_end_object_materials();
+
+                               /* set default specular */
+                               GPU_basic_shader_colors(NULL, specular, 35, 
1.0f);
+                               GPU_basic_shader_bind(GPU_SHADER_LIGHTING | 
GPU_SHADER_USE_COLOR);
+
+                               dm->drawMappedFaces(dm, NULL, NULL, NULL, NULL, 
DM_DRAW_USE_COLORS | DM_DRAW_NEED_NORMALS);
+
+                               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+                       }
+               }
+               else {


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to