Merged changes in the trunk up to revision 42116.
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 5521460ac14f150a9bb7e75745d479923f8385a8..be3a599330b15fe65d56c25f5d763c4cacb6b90b 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -38,6 +36,7 @@
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_constraint_types.h" // for drawing constraint
+#include "DNA_dynamicpaint_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_material_types.h"
@@ -57,6 +56,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_anim.h"                  //for the where_on_path function
+#include "BKE_camera.h"
 #include "BKE_constraint.h" // for the get_constraint_target function
 #include "BKE_curve.h"
 #include "BKE_DerivedMesh.h"
@@ -77,6 +77,8 @@
 #include "BKE_pointcache.h"
 #include "BKE_scene.h"
 #include "BKE_unit.h"
+#include "BKE_movieclip.h"
+#include "BKE_tracking.h"
 
 #include "smoke_API.h"
 
 
 
 /* this condition has been made more complex since editmode can draw textures */
-#define CHECK_OB_DRAWTEXTURE(vd, dt) \
-       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) || \
+#define CHECK_OB_DRAWTEXTURE(vd, dt)                                          \
+       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) ||          \
        (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
-static void draw_bounding_volume(Scene *scene, Object *ob);
+typedef enum eWireDrawMode {
+       OBDRAW_WIRE_OFF= 0,
+       OBDRAW_WIRE_ON= 1,
+       OBDRAW_WIRE_ON_DEPTH= 2
+} eWireDrawMode;
+
+static void draw_bounding_volume(Scene *scene, Object *ob, char type);
 
 static void drawcube_size(float size);
 static void drawcircle_size(float size);
@@ -203,6 +211,40 @@ static void view3d_project_short_noclip(ARegion *ar, const float vec[3], short *
        }
 }
 
+/* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
+static void view3d_project_short_clip_persmat(ARegion *ar, float *vec, short *adr, int local)
+{
+       RegionView3D *rv3d= ar->regiondata;
+       float fx, fy, vec4[4];
+
+       adr[0]= IS_CLIPPED;
+
+       /* clipplanes in eye space */
+       if(rv3d->rflag & RV3D_CLIPPING) {
+               if(ED_view3d_test_clipping(rv3d, vec, local))
+                       return;
+       }
+
+       copy_v3_v3(vec4, vec);
+       vec4[3]= 1.0;
+
+       mul_m4_v4(rv3d->persmat, vec4);
+
+       /* clipplanes in window space */
+       if( vec4[3] > (float)BL_NEAR_CLIP ) {   /* is the NEAR clipping cutoff for picking */
+               fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
+
+               if( fx>0 && fx<ar->winx) {
+
+                       fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
+
+                       if(fy > 0.0f && fy < (float)ar->winy) {
+                               adr[0]= (short)floorf(fx);
+                               adr[1]= (short)floorf(fy);
+                       }
+               }
+       }
+}
 /* ************************ */
 
 /* check for glsl drawing */
@@ -736,7 +778,12 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
        for(vos= strings->first; vos; vos= vos->next) {
                if(mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
                        mul_m4_v3(mat, vos->vec);
-               view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
+
+               if(vos->flag&V3D_CACHE_TEXT_GLOBALSPACE)
+                       view3d_project_short_clip_persmat(ar, vos->vec, vos->sco, 0);
+               else
+                       view3d_project_short_clip(ar, vos->vec, vos->sco, 0);
+
                if(vos->sco[0]!=IS_CLIPPED)
                        tot++;
        }
@@ -768,7 +815,7 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
                else glDepthMask(0);
                
                for(vos= strings->first; vos; vos= vos->next) {
-#if 0       // too slow, reading opengl info while drawing is very bad, better to see if we cn use the zbuffer while in pixel space - campbell
+#if 0       // too slow, reading opengl info while drawing is very bad, better to see if we can use the zbuffer while in pixel space - campbell
                        if(v3d->zbuf && (vos->flag & V3D_CACHE_TEXT_ZBUF)) {
                                gluProject(vos->vec[0], vos->vec[1], vos->vec[2], mats.modelview, mats.projection, (GLint *)mats.viewport, &ux, &uy, &uz);
                                glReadPixels(ar->winrct.xmin+vos->mval[0]+vos->xoffs, ar->winrct.ymin+vos->mval[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
@@ -1052,7 +1099,12 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        /* cone can't be drawn for duplicated lamps, because duplilist would be freed to */
        /* the moment of view3d_draw_transp() call */
        const short is_view= (rv3d->persp==RV3D_CAMOB && v3d->camera == base->object);
-       const short drawcone= (dt>OB_WIRE && !(G.f & G_PICKSEL) && (la->type == LA_SPOT) && (la->mode & LA_SHOW_CONE) && !(base->flag & OB_FROMDUPLI) && !is_view);
+       const short drawcone= ((dt > OB_WIRE) &&
+                              !(G.f & G_PICKSEL) &&
+                              (la->type == LA_SPOT) &&
+                              (la->mode & LA_SHOW_CONE) &&
+                              !(base->flag & OB_FROMDUPLI) &&
+                              !is_view);
 
        if(drawcone && !v3d->transp) {
                /* in this case we need to draw delayed */
@@ -1368,16 +1420,203 @@ float view3d_camera_border_hack_col[4];
 short view3d_camera_border_hack_test= FALSE;
 #endif
 
+/* ****************** draw clip data *************** */
+
+static void draw_bundle_sphere(void)
+{
+       static GLuint displist= 0;
+
+       if (displist == 0) {
+               GLUquadricObj *qobj;
+
+               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();
+       }
+
+       glCallList(displist);
+}
+
+static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip, int flag)
+{
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingTrack *track;
+       float mat[4][4], imat[4][4], curcol[4];
+       unsigned char col[4], scol[4];
+       int bundlenr= 1;
+
+       if((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0)
+               return;
+
+       if(v3d->flag2&V3D_RENDER_OVERRIDE)
+               return;
+
+       glGetFloatv(GL_CURRENT_COLOR, curcol);
+
+       UI_GetThemeColor4ubv(TH_TEXT, col);
+       UI_GetThemeColor4ubv(TH_SELECT, scol);
+
+       BKE_get_tracking_mat(scene, base->object, mat);
+
+       glEnable(GL_LIGHTING);
+       glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+       glEnable(GL_COLOR_MATERIAL);
+       glShadeModel(GL_SMOOTH);
+
+       /* current ogl matrix is translated in camera space, bundles should
+          be rendered in world space, so camera matrix should be "removed"
+          from current ogl matrix */
+       invert_m4_m4(imat, base->object->obmat);
+
+       glPushMatrix();
+       glMultMatrixf(imat);
+       glMultMatrixf(mat);
+
+       for ( track= tracking->tracks.first; track; track= track->next) {
+               int selected= track->flag&SELECT || track->pat_flag&SELECT || track->search_flag&SELECT;
+               if((track->flag&TRACK_HAS_BUNDLE)==0)
+                       continue;
+
+               if(flag&DRAW_PICKING)
+                       glLoadName(base->selcol + (bundlenr<<16));
+
+               glPushMatrix();
+                       glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
+                       glScalef(v3d->bundle_size/0.05f, v3d->bundle_size/0.05f, v3d->bundle_size/0.05f);
+
+                       if(v3d->drawtype==OB_WIRE) {
+                               glDisable(GL_LIGHTING);
+                               glDepthMask(0);
+
+                               if(selected) {
+                                       if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                       else UI_ThemeColor(TH_SELECT);
+                               } else {
+                                       if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                       else UI_ThemeColor(TH_WIRE);
+                               }
+
+                               drawaxes(0.05f, v3d->bundle_drawtype);
+
+                               glDepthMask(1);
+                               glEnable(GL_LIGHTING);
+                       } else if(v3d->drawtype>OB_WIRE) {
+                               if(v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
+                                       /* selection outline */
+                                       if(selected) {
+                                               if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                               else UI_ThemeColor(TH_SELECT);
+
+                                               glDepthMask(0);
+                                               glLineWidth(2.f);
+                                               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.f);
+                                               glDepthMask(1);
+                                       }
+
+                                       if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                       else UI_ThemeColor(TH_BUNDLE_SOLID);
+
+                                       draw_bundle_sphere();
+                               } else {
+                                       glDisable(GL_LIGHTING);
+                                       glDepthMask(0);
+
+                                       if(selected) {
+                                               if(base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                               else UI_ThemeColor(TH_SELECT);
+                                       } else {
+                                               if(track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                               else UI_ThemeColor(TH_WIRE);
+                                       }
+
+                                       drawaxes(0.05f, v3d->bundle_drawtype);
+
+                                       glDepthMask(1);
+                                       glEnable(GL_LIGHTING);
+                               }
+                       }
+
+               glPopMatrix();
+
+               if((flag & DRAW_PICKING)==0 && (v3d->flag2&V3D_SHOW_BUNDLENAME)) {
+                       float pos[3];
+                       unsigned char tcol[4];
+
+                       if(selected) memcpy(tcol, scol, sizeof(tcol));
+                       else memcpy(tcol, col, sizeof(tcol));
+
+                       mul_v3_m4v3(pos, mat, track->bundle_pos);
+                       view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
+               }
+
+               bundlenr++;
+       }
+
+       if((flag & DRAW_PICKING)==0) {
+               if(v3d->flag2&V3D_SHOW_CAMERAPATH && clip->tracking.reconstruction.camnr) {
+                       int a= 0;
+                       MovieTrackingReconstruction *reconstruction= &tracking->reconstruction;
+                       MovieReconstructedCamera *camera= tracking->reconstruction.cameras;
+
+                       glDisable(GL_LIGHTING);
+                       UI_ThemeColor(TH_CAMERA_PATH);
+                       glLineWidth(2.0f);
+
+                       glBegin(GL_LINE_STRIP);
+                               for(a= 0; a<reconstruction->camnr; a++, camera++) {
+                                       glVertex3fv(camera->mat[3]);
+                               }
+                       glEnd();
+
+                       glLineWidth(1.0f);
+                       glEnable(GL_LIGHTING);
+               }
+       }
+
+       glPopMatrix();
+
+       /* restore */
+       glShadeModel(GL_FLAT);
+       glDisable(GL_COLOR_MATERIAL);
+       glDisable(GL_LIGHTING);
+
+       glColor4fv(curcol);
+
+       if(flag&DRAW_PICKING)
+               glLoadName(base->selcol);
+}
+
 /* flag similar to draw_object() */
-static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, int flag)
+static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int flag)
 {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
+       Object *ob= base->object;
        float tvec[3];
        float vec[4][3], asp[2], shift[2], scale[3];
        int i;
        float drawsize;
        const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
+       MovieClip *clip= object_get_movieclip(scene, base->object, 0);
+
+       /* draw data for movie clip set as active for scene */
+       if(clip)
+               draw_viewport_reconstruction(scene, base, v3d, clip, flag);
 
 #ifdef VIEW3D_CAMERA_BORDER_HACK
        if(is_view && !(G.f & G_PICKSEL)) {
@@ -1465,7 +1704,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
                        if(cam->flag & CAM_SHOWLIMITS) {
                                draw_limit_line(cam->clipsta, cam->clipend, 0x77FFFF);
                                /* qdn: was yafray only, now also enabled for Blender to be used with defocus composit node */
-                               draw_focus_cross(dof_camera(ob), cam->drawsize);
+                               draw_focus_cross(object_camera_dof_distance(ob), cam->drawsize);
                        }
 
                        wrld= scene->world;
@@ -1492,8 +1731,8 @@ static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D
 
                glBegin(GL_LINE_LOOP);
                for(i = 0; i < 16; i++) {
-                       vec[0] = cosf(M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
-                       vec[1] = sinf(M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+                       vec[0] = cosf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+                       vec[1] = sinf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
                        glVertex3fv(vec);
                }
                glEnd();
@@ -1578,7 +1817,7 @@ static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, i
                float col[3];
                MDeformWeight *mdw= defvert_find_index (lt->dvert+index, use_wcol-1);
                
-               weight_to_rgb(mdw?mdw->weight:0.0f, col, col+1, col+2);
+               weight_to_rgb(col, mdw?mdw->weight:0.0f);
                glColor3fv(col);
 
        }
@@ -2062,21 +2301,32 @@ static void draw_dm_edges_sharp(DerivedMesh *dm)
        dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, NULL);
 }
 
+       /* Draw only Freestyle feature edges */
+static int draw_dm_edges_freestyle__setDrawOptions(void *UNUSED(userData), int index)
+{
+       EditEdge *eed = EM_get_edge_for_index(index);
+
+       return (eed->h==0 && eed->freestyle);
+}
+static void draw_dm_edges_freestyle(DerivedMesh *dm)
+{
+       dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, NULL);
+}
 
        /* Draw faces with color set based on selection
         * return 2 for the active face so it renders with stipple enabled */
 static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r))
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
+       struct { unsigned char *cols[4]; EditFace *efa_act; } * data = userData;
        EditFace *efa = EM_get_face_for_index(index);
        unsigned char *col;
        
        if (efa->h==0) {
                if (efa == data->efa_act) {
-                       glColor4ubv(data->cols[2]);
+                       glColor4ubv(data->cols[3]);
                        return 2; /* stipple */
                } else {
-                       col = data->cols[(efa->f&SELECT)?1:0];
+                       col = data->cols[(efa->f & SELECT) ? 1 : (efa->flag & ME_FREESTYLE_FACE) ? 2 : 0];
                        if (col[3]==0) return 0;
                        glColor4ubv(col);
                        return 1;
@@ -2087,7 +2337,7 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNU
 
 static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index)
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } * data = userData;
+       struct { unsigned char *cols[4]; EditFace *efa_act; } * data = userData;
        EditFace *efa = EM_get_face_for_index(index);
        EditFace *next_efa = EM_get_face_for_index(next_index);
        unsigned char *col, *next_col;
@@ -2098,8 +2348,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
        if(efa == data->efa_act || next_efa == data->efa_act)
                return 0;
 
-       col = data->cols[(efa->f&SELECT)?1:0];
-       next_col = data->cols[(next_efa->f&SELECT)?1:0];
+       col = data->cols[(efa->f & SELECT) ? 1 : (efa->flag & ME_FREESTYLE_FACE) ? 2 : 0];
+       next_col = data->cols[(next_efa->f & SELECT) ? 1 : (next_efa->flag & ME_FREESTYLE_FACE) ? 2 : 0];
 
        if(col[3]==0 || next_col[3]==0)
                return 0;
@@ -2108,12 +2358,13 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
 }
 
 /* also draws the active face */
-static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *actCol, EditFace *efa_act) 
+static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *markCol, unsigned char *actCol, EditFace *efa_act) 
 {
-       struct { unsigned char *cols[3]; EditFace *efa_act; } data;
+       struct { unsigned char *cols[4]; EditFace *efa_act; } data;
        data.cols[0] = baseCol;
        data.cols[1] = selCol;
-       data.cols[2] = actCol;
+       data.cols[2] = markCol;
+       data.cols[3] = actCol;
        data.efa_act = efa_act;
 
        dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, &data, 0, GPU_enable_material, draw_dm_faces_sel__compareDrawOptions);
@@ -2336,7 +2587,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                                copy_v3_v3(v1, eed->v1->co);
                                copy_v3_v3(v2, eed->v2->co);
 
-                               interp_v3_v3v3(vmid, v1, v2, 0.5f);
+                               mid_v3_v3v3(vmid, v1, v2);
 
                                if(do_global) {
                                        mul_mat3_m4_v3(ob->obmat, v1);
@@ -2508,11 +2759,11 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                if(CHECK_OB_DRAWTEXTURE(v3d, dt)) {
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
                                glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
-
+                               
                                finalDM->drawMappedFacesGLSL(finalDM, GPU_enable_material,
-                                       draw_em_fancy__setGLSLFaceOpts, NULL);
+                                                            draw_em_fancy__setGLSLFaceOpts, NULL);
                                GPU_disable_material();
-
+                               
                                glFrontFace(GL_CCW);
                        }
                        else {
@@ -2522,12 +2773,12 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                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);
-
+                       
                        glEnable(GL_LIGHTING);
                        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
-
+                       
                        finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, NULL, 0, GPU_enable_material, NULL);
-
+                       
                        glFrontFace(GL_CCW);
                        glDisable(GL_LIGHTING);
                }
@@ -2547,11 +2798,12 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
        }
        
        if(me->drawflag & ME_DRAWFACES) {       /* transp faces */
-               unsigned char col1[4], col2[4], col3[4];
+               unsigned char col1[4], col2[4], col3[4], col4[4];
                        
                UI_GetThemeColor4ubv(TH_FACE, col1);
                UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
-               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
+               UI_GetThemeColor4ubv(TH_FREESTYLE_FACE_MARK, col3);
+               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
                
                glEnable(GL_BLEND);
                glDepthMask(0);         // disable write in zbuffer, needed for nice transp
@@ -2560,7 +2812,10 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                if CHECK_OB_DRAWTEXTURE(v3d, dt)
                        col1[3] = 0;
                
-               draw_dm_faces_sel(cageDM, col1, col2, col3, efa_act);
+               if (!(me->drawflag & ME_DRAW_FREESTYLE_FACE))
+                       col3[3] = 0;
+
+               draw_dm_faces_sel(cageDM, col1, col2, col3, col4, efa_act);
 
                glDisable(GL_BLEND);
                glDepthMask(1);         // restore write in zbuffer
@@ -2568,14 +2823,14 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                /* even if draw faces is off it would be nice to draw the stipple face
                 * Make all other faces zero alpha except for the active
                 * */
-               unsigned char col1[4], col2[4], col3[4];
-               col1[3] = col2[3] = 0; /* dont draw */
-               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
+               unsigned char col1[4], col2[4], col3[4], col4[4];
+               col1[3] = col2[3] = col3[3] = 0; /* dont draw */
+               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
                
                glEnable(GL_BLEND);
                glDepthMask(0);         // disable write in zbuffer, needed for nice transp
                
-               draw_dm_faces_sel(cageDM, col1, col2, col3, efa_act);
+               draw_dm_faces_sel(cageDM, col1, col2, col3, col4, efa_act);
 
                glDisable(GL_BLEND);
                glDepthMask(1);         // restore write in zbuffer
@@ -2610,6 +2865,16 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                        glLineWidth(1);
                }
        
+               if(me->drawflag & ME_DRAW_FREESTYLE_EDGE) {
+                       UI_ThemeColor(TH_FREESTYLE_EDGE_MARK);
+                       glLineWidth(2);
+       
+                       draw_dm_edges_freestyle(cageDM);
+       
+                       glColor3ub(0,0,0);
+                       glLineWidth(1);
+               }
+       
                if(me->drawflag & ME_DRAWCREASES) {
                        draw_dm_creases(cageDM);
                }
@@ -2684,16 +2949,36 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        Mesh *me = ob->data;
        Material *ma= give_current_material(ob, 1);
        const short hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
-       const short is_paint_sel= (ob==OBACT && paint_facesel_test(ob));
-       int draw_wire = 0;
+       eWireDrawMode draw_wire= OBDRAW_WIRE_OFF;
        int /* totvert,*/ totedge, totface;
        DerivedMesh *dm= mesh_get_derived_final(scene, ob, scene->customdata_mask);
+       ModifierData *md = NULL;
+       int draw_flags = (ob==OBACT && paint_facesel_test(ob)) ? DRAW_FACE_SELECT : 0;
 
        if(!dm)
                return;
-       
-       if (ob->dtx&OB_DRAWWIRE) {
-               draw_wire = 2; /* draw wire after solid using zoffset and depth buffer adjusment */
+
+       /* check to draw dynamic paint colors */
+       if ((md = modifiers_findByType(ob, eModifierType_DynamicPaint)))
+       {
+               /* check if target has an active dpaint modifier        */
+               if(md && (md->mode & eModifierMode_Realtime))                                   
+               {
+                       DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
+                       /* if canvas is ready to preview vertex colors */
+                       if (pmd->canvas && pmd->canvas->flags & MOD_DPAINT_PREVIEW_READY &&
+                               DM_get_face_data_layer(dm, CD_WEIGHT_MCOL)) {
+                               draw_flags |= DRAW_DYNAMIC_PAINT_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_DEPTH; /* draw wire after solid using zoffset and depth buffer adjusment */
        }
        
        /* totvert = dm->getNumVerts(dm); */ /*UNUSED*/
@@ -2703,12 +2988,9 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        /* vertexpaint, faceselect wants this, but it doesnt work for shaded? */
        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
-               // Unwanted combination.
-       if (is_paint_sel) draw_wire = 0;
-
        if(dt==OB_BOUNDBOX) {
                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                       draw_bounding_volume(scene, ob);
+                       draw_bounding_volume(scene, ob, ob->boundtype);
        }
        else if(hasHaloMat || (totface==0 && totedge==0)) {
                glPointSize(1.5);
@@ -2716,16 +2998,21 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                glPointSize(1.0);
        }
        else if(dt==OB_WIRE || totface==0) {
-               draw_wire = 1; /* draw wire only, no depth buffer stuff  */
+               draw_wire= OBDRAW_WIRE_ON; /* draw wire only, no depth buffer stuff  */
        }
-       else if(        (is_paint_sel || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
-                               CHECK_OB_DRAWTEXTURE(v3d, dt))
+       else if ( (draw_flags & DRAW_FACE_SELECT || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
+                 CHECK_OB_DRAWTEXTURE(v3d, dt))
        {
-               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || is_paint_sel) && !draw_wire) {
+               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(v3d, ob, dm);
                }
 
-               if(draw_glsl_material(scene, ob, v3d, dt)) {
+               if(draw_glsl_material(scene, ob, v3d, dt) && !(draw_flags & DRAW_DYNAMIC_PAINT_PREVIEW)) {
                        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                        dm->drawFacesGLSL(dm, GPU_enable_material);
@@ -2736,10 +3023,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glFrontFace(GL_CCW);
                }
                else {
-                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, is_paint_sel);
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, draw_flags);
                }
 
-               if(!is_paint_sel) {
+               if(!(draw_flags & DRAW_FACE_SELECT)) {
                        if(base->flag & SELECT)
                                UI_ThemeColor((ob==OBACT)?TH_ACTIVE:TH_SELECT);
                        else
@@ -2773,13 +3060,57 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        GPU_disable_material();
                        
                        /* since we already draw wire as wp guide, dont draw over the top */
-                       draw_wire= 0;
+                       draw_wire= OBDRAW_WIRE_OFF;
+               }
+               else if (draw_flags & DRAW_DYNAMIC_PAINT_PREVIEW) {
+                       /* for object selection draws no shade */
+                       if (flag & (DRAW_PICKING|DRAW_CONSTCOLOR)) {
+                               dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
+                       }
+                       else {
+                               /* draw outline */
+                               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(v3d, ob, dm);
+                               }
+
+                               /* materials arent compatible with vertex colors */
+                               GPU_end_object_materials();
+
+                               GPU_enable_material(0, NULL);
+                               
+                               /* set default spec */
+                               glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
+                               glEnable(GL_COLOR_MATERIAL);    /* according manpages needed */
+                               glColor3ub(120, 120, 120);
+                               glDisable(GL_COLOR_MATERIAL);
+                               /* diffuse */
+                               glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+                               glEnable(GL_LIGHTING);
+                               glEnable(GL_COLOR_MATERIAL);
+
+                               dm->drawMappedFaces(dm, NULL, NULL, 1, GPU_enable_material, NULL);
+                               glDisable(GL_COLOR_MATERIAL);
+                               glDisable(GL_LIGHTING);
+
+                               GPU_disable_material();
+                       }
                }
                else {
                        Paint *p;
 
-                       if((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !draw_wire && !ob->sculpt)
+                       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(v3d, ob, dm);
+                       }
 
                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED );
 
@@ -2873,7 +3204,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        }
                }
        }
-       if (draw_wire) {
+       if (draw_wire != OBDRAW_WIRE_OFF) {
 
                /* When using wireframe object traw in particle edit mode
                 * the mesh gets in the way of seeing the particles, fade the wire color
@@ -2896,7 +3227,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                 * if draw wire is 1 then just drawing wire, no need for depth buffer stuff,
                 * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks.
                 */
-               if (dt!=OB_WIRE && draw_wire==2) {
+               if (dt!=OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
                        bglPolygonOffset(rv3d->dist, 1.0);
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
@@ -2904,7 +3235,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_SOLID)==0)
                        dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag & ME_ALLEDGES);
 
-               if (dt!=OB_WIRE && draw_wire==2) {
+               if (dt!=OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
                        glDepthMask(1);
                        bglPolygonOffset(rv3d->dist, 0.0);
                }
@@ -2959,15 +3290,11 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
 
                if(dt>OB_WIRE) {
                        glsl = draw_glsl_material(scene, ob, v3d, dt);
-                       check_alpha = check_material_alpha(base, glsl);
 
-                       GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl,
-                                       (check_alpha)? &do_alpha_pass: NULL);
+                       GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
                }
 
-               // transp in editmode makes the fancy draw over go bad
-               if (!do_alpha_pass)
-                       draw_em_fancy(scene, v3d, rv3d, ob, em, cageDM, finalDM, dt);
+               draw_em_fancy(scene, v3d, rv3d, ob, em, cageDM, finalDM, dt);
 
                GPU_end_object_materials();
 
@@ -3420,19 +3747,15 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
        float vec[3], vec2[3];
        float *vd = NULL;
        float *cd = NULL;
-       float ma_r=0.0f;
-       float ma_g=0.0f;
-       float ma_b=0.0f;
+       float ma_col[3]= {0.0f, 0.0f, 0.0f};
 
        /* null only for PART_DRAW_CIRC */
        if(pdd) {
                vd = pdd->vd;
                cd = pdd->cd;
 
-               if(pdd->ma_r) {
-                       ma_r = *pdd->ma_r;
-                       ma_g = *pdd->ma_g;
-                       ma_b = *pdd->ma_b;
+               if(pdd->ma_col) {
+                       copy_v3_v3(ma_col, pdd->ma_col);
                }
        }
 
@@ -3443,9 +3766,7 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                                copy_v3_v3(vd,state->co); pdd->vd+=3;
                        }
                        if(cd) {
-                               cd[0]=ma_r;
-                               cd[1]=ma_g;
-                               cd[2]=ma_b;
+                               copy_v3_v3(cd, pdd->ma_col);
                                pdd->cd+=3;
                        }
                        break;
@@ -3471,9 +3792,9 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                        }
                        else {
                                if(cd) {
-                                       cd[0]=cd[3]=cd[6]=cd[9]=cd[12]=cd[15]=ma_r;
-                                       cd[1]=cd[4]=cd[7]=cd[10]=cd[13]=cd[16]=ma_g;
-                                       cd[2]=cd[5]=cd[8]=cd[11]=cd[14]=cd[17]=ma_b;
+                                       cd[0]=cd[3]=cd[6]=cd[ 9]=cd[12]=cd[15]= ma_col[0];
+                                       cd[1]=cd[4]=cd[7]=cd[10]=cd[13]=cd[16]= ma_col[1];
+                                       cd[2]=cd[5]=cd[8]=cd[11]=cd[14]=cd[17]= ma_col[2];
                                        pdd->cd+=18;
                                }
                                sub_v3_v3v3(vec2, state->co, vec);
@@ -3518,9 +3839,9 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                        madd_v3_v3v3fl(pdd->vd, state->co, vec, -draw_line[0]); pdd->vd+=3;
                        madd_v3_v3v3fl(pdd->vd, state->co, vec,  draw_line[1]); pdd->vd+=3;
                        if(cd) {
-                               cd[0]=cd[3]=ma_r;
-                               cd[1]=cd[4]=ma_g;
-                               cd[2]=cd[5]=ma_b;
+                               cd[0]=cd[3]= ma_col[0];
+                               cd[1]=cd[4]= ma_col[1];
+                               cd[2]=cd[5]= ma_col[2];
                                pdd->cd+=6;
                        }
                        break;
@@ -3534,9 +3855,9 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                {
                        float xvec[3], yvec[3], zvec[3], bb_center[3];
                        if(cd) {
-                               cd[0]=cd[3]=cd[6]=cd[9]=ma_r;
-                               cd[1]=cd[4]=cd[7]=cd[10]=ma_g;
-                               cd[2]=cd[5]=cd[8]=cd[11]=ma_b;
+                               cd[0]=cd[3]=cd[6]=cd[ 9]= ma_col[0];
+                               cd[1]=cd[4]=cd[7]=cd[10]= ma_col[1];
+                               cd[2]=cd[5]=cd[8]=cd[11]= ma_col[2];
                                pdd->cd+=12;
                        }
 
@@ -3591,7 +3912,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
        float timestep, pixsize=1.0, pa_size, r_tilt, r_length;
        float pa_time, pa_birthtime, pa_dietime, pa_health, intensity;
        float cfra;
-       float ma_r=0.0f, ma_g=0.0f, ma_b=0.0f;
+       float ma_col[3]= {0.0f, 0.0f, 0.0f};
        int a, totpart, totpoint=0, totve=0, drawn, draw_as, totchild=0;
        int select=ob->flag&SELECT, create_cdata=0, need_v=0;
        GLint polygonmode[2];
@@ -3655,10 +3976,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 
        if((ma) && (part->draw_col == PART_DRAW_COL_MAT)) {
                rgb_float_to_byte(&(ma->r), tcol);
-
-               ma_r = ma->r;
-               ma_g = ma->g;
-               ma_b = ma->b;
+               copy_v3_v3(ma_col, &ma->r);
        }
 
        glColor3ubv(tcol);
@@ -3676,7 +3994,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 
        totpart=psys->totpart;
 
-       cfra= bsystem_time(scene, NULL, (float)CFRA, 0.0f);
+       cfra= BKE_curframe(scene);
 
        if(draw_as==PART_DRAW_PATH && psys->pathcache==NULL && psys->childcache==NULL)
                draw_as=PART_DRAW_DOT;
@@ -3824,9 +4142,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
        }
 
        if(pdd) {
-               pdd->ma_r = &ma_r;
-               pdd->ma_g = &ma_g;
-               pdd->ma_b = &ma_b;
+               pdd->ma_col= ma_col;
        }
 
        psys->lattice= psys_get_lattice(&sim);
@@ -3868,7 +4184,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                                                        intensity= 1.0f; /* should never happen */
                                        }
                                        CLAMP(intensity, 0.f, 1.f);
-                                       weight_to_rgb(intensity, &ma_r, &ma_g, &ma_b);
+                                       weight_to_rgb(ma_col, intensity);
                                }
                        }
                        else{
@@ -4129,7 +4445,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                }
 
                /* restore from select */
-               glColor3f(ma_r,ma_g,ma_b);
+               glColor3fv(ma_col);
                glPointSize(part->draw_size ? part->draw_size : 2.0);
                glLineWidth(1.0);
 
@@ -4194,7 +4510,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 
        if(pdd) {
                /* drop references to stack memory */
-               pdd->ma_r= pdd->ma_g= pdd->ma_b= NULL;
+               pdd->ma_col= NULL;
        }
 
        if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
@@ -4925,7 +5241,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        int skip= nu->resolu/16;
                        
                        while (nr-->0) { /* accounts for empty bevel lists */
-                               float fac= bevp->radius * ts->normalsize;
+                               const float fac= bevp->radius * ts->normalsize;
                                float vec_a[3]; // Offset perpendicular to the curve
                                float vec_b[3]; // Delta along the curve
 
@@ -4941,9 +5257,9 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                                mul_qt_v3(bevp->quat, vec_b);
                                add_v3_v3(vec_a, bevp->vec);
                                add_v3_v3(vec_b, bevp->vec);
-                               
-                               VECSUBFAC(vec_a, vec_a, bevp->dir, fac);
-                               VECSUBFAC(vec_b, vec_b, bevp->dir, fac);
+
+                               madd_v3_v3fl(vec_a, bevp->dir, -fac);
+                               madd_v3_v3fl(vec_b, bevp->dir, -fac);
 
                                glBegin(GL_LINE_STRIP);
                                glVertex3fv(vec_a);
@@ -5474,7 +5790,7 @@ static void get_local_bounds(Object *ob, float center[3], float size[3])
 }
 #endif
 
-static void draw_bb_quadric(BoundBox *bb, short type)
+static void draw_bb_quadric(BoundBox *bb, char type)
 {
        float size[3], cent[3];
        GLUquadricObj *qobj = gluNewQuadric(); 
@@ -5513,7 +5829,7 @@ static void draw_bb_quadric(BoundBox *bb, short type)
        gluDeleteQuadric(qobj); 
 }
 
-static void draw_bounding_volume(Scene *scene, Object *ob)
+static void draw_bounding_volume(Scene *scene, Object *ob, char type)
 {
        BoundBox *bb= NULL;
        
@@ -5539,8 +5855,8 @@ static void draw_bounding_volume(Scene *scene, Object *ob)
        
        if(bb==NULL) return;
        
-       if(ob->boundtype==OB_BOUND_BOX) draw_box(bb->vec);
-       else draw_bb_quadric(bb, ob->boundtype);
+       if(type==OB_BOUND_BOX) draw_box(bb->vec);
+       else draw_bb_quadric(bb, type);
        
 }
 
@@ -5752,7 +6068,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        Object *ob;
        Curve *cu;
        RegionView3D *rv3d= ar->regiondata;
-       //float cfraont;
        float vec1[3], vec2[3];
        unsigned int col=0;
        int /*sel, drawtype,*/ colindex= 0;
@@ -5791,83 +6106,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        /* no return after this point, otherwise leaks */
        view3d_cached_text_draw_begin();
        
-
-       /* draw keys? */
-#if 0 // XXX old animation system
-       if(base==(scene->basact) || (base->flag & (SELECT+BA_WAS_SEL))) {
-               if(flag==0 && warning_recursive==0 && ob!=scene->obedit) {
-                       if(ob->ipo && ob->ipo->showkey && (ob->ipoflag & OB_DRAWKEY)) {
-                               ListBase elems;
-                               CfraElem *ce;
-                               float temp[7][3];
-
-                               warning_recursive= 1;
-
-                               elems.first= elems.last= 0;
-                               // warning: no longer checks for certain ob-keys only... (so does this need to use the proper ipokeys then?)
-                               make_cfra_list(ob->ipo, &elems); 
-
-                               cfraont= (scene->r.cfra);
-                               drawtype= v3d->drawtype;
-                               if(drawtype>OB_WIRE) v3d->drawtype= OB_WIRE;
-                               sel= base->flag;
-                               memcpy(temp, &ob->loc, 7*3*sizeof(float));
-
-                               ipoflag= ob->ipoflag;
-                               ob->ipoflag &= ~OB_OFFS_OB;
-
-                               set_no_parent_ipo(1);
-                               disable_speed_curve(1);
-
-                               if ((ob->ipoflag & OB_DRAWKEYSEL)==0) {
-                                       ce= elems.first;
-                                       while(ce) {
-                                               if(!ce->sel) {
-                                                       (scene->r.cfra)= ce->cfra/scene->r.framelen;
-
-                                                       base->flag= 0;
-
-                                                       where_is_object_time(scene, ob, (scene->r.cfra));
-                                                       draw_object(scene, ar, v3d, base, 0);
-                                               }
-                                               ce= ce->next;
-                                       }
-                               }
-
-                               ce= elems.first;
-                               while(ce) {
-                                       if(ce->sel) {
-                                               (scene->r.cfra)= ce->cfra/scene->r.framelen;
-
-                                               base->flag= SELECT;
-
-                                               where_is_object_time(scene, ob, (scene->r.cfra));
-                                               draw_object(scene, ar, v3d, base, 0);
-                                       }
-                                       ce= ce->next;
-                               }
-
-                               set_no_parent_ipo(0);
-                               disable_speed_curve(0);
-
-                               base->flag= sel;
-                               ob->ipoflag= ipoflag;
-
-                               /* restore icu->curval */
-                               (scene->r.cfra)= cfraont;
-
-                               memcpy(&ob->loc, temp, 7*3*sizeof(float));
-                               where_is_object(scene, ob);
-                               v3d->drawtype= drawtype;
-
-                               BLI_freelistN(&elems);
-
-                               warning_recursive= 0;
-                       }
-               }
-       }
-#endif // XXX old animation system
-
        /* patch? children objects with a timeoffs change the parents. How to solve! */
        /* if( ((int)ob->ctime) != F_(scene->r.cfra)) where_is_object(scene, ob); */
        
@@ -5925,7 +6163,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        if(base->flag & (SELECT+BA_WAS_SEL)) {
                                                /* uses darker active color for non-active + selected*/
                                                theme_id= TH_GROUP_ACTIVE;
-
+                                               
                                                if(scene->basact != base) {
                                                        theme_shade= -16;
                                                }
@@ -6106,7 +6344,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else if(ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb))
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
@@ -6122,7 +6360,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else if(ED_view3d_boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
@@ -6139,7 +6377,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                drawmball(scene, v3d, rv3d, base, dt);
                        else if(dt==OB_BOUNDBOX) {
                                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
-                                       draw_bounding_volume(scene, ob);
+                                       draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        else 
                                empty_object= drawmball(scene, v3d, rv3d, base, dt);
@@ -6163,7 +6401,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        break;
                case OB_CAMERA:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0 || (rv3d->persp==RV3D_CAMOB && v3d->camera==ob)) /* special exception for active camera */
-                               drawcamera(scene, v3d, rv3d, ob, flag);
+                               drawcamera(scene, v3d, rv3d, base, flag);
                        break;
                case OB_SPEAKER:
                        if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
@@ -6381,6 +6619,14 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        }
                }
 
+               if(ob->gameflag & OB_BOUNDS) {
+                       if(ob->boundtype!=ob->collision_boundtype || (dtx & OB_BOUNDBOX)==0) {
+                               setlinestyle(2);
+                               draw_bounding_volume(scene, ob, ob->collision_boundtype);
+                               setlinestyle(0);
+                       }
+               }
+
                /* draw extra: after normal draw because of makeDispList */
                if(dtx && (G.f & G_RENDER_OGL)==0) {
 
@@ -6388,8 +6634,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                drawaxes(1.0f, OB_ARROWS);
                        }
                        if(dtx & OB_BOUNDBOX) {
-                               if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
-                                       draw_bounding_volume(scene, ob);
+                               draw_bounding_volume(scene, ob, ob->boundtype);
                        }
                        if(dtx & OB_TEXSPACE) drawtexspace(ob);
                        if(dtx & OB_DRAWNAME) {
@@ -6507,7 +6752,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        for (ct= targets.first; ct; ct= ct->next) {
                                                /* calculate target's matrix */
                                                if (cti->get_target_matrix) 
-                                                       cti->get_target_matrix(curcon, cob, ct, bsystem_time(scene, ob, (float)(scene->r.cfra), give_timeoffset(ob)));
+                                                       cti->get_target_matrix(curcon, cob, ct, BKE_curframe(scene));
                                                else
                                                        unit_m4(ct->matrix);
                                                
@@ -6727,7 +6972,10 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                }
                else {
                        Mesh *me= ob->data;
-                       if(me->editflag & ME_EDIT_VERT_SEL) {
+                       if(     (me->editflag & ME_EDIT_VERT_SEL) &&
+                               /* currently vertex select only supports weight paint */
+                               (ob->mode & OB_MODE_WEIGHT_PAINT))
+                       {
                                DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
                                glColor3ub(0, 0, 0);