- added GCC warning -Wstrict-prototypes
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 17ab6a3f965ef888daf0d1669b58285a5018be0c..65b621b1d7a3928289abedb1fa114e05d9d1f8ee 100644 (file)
 #include <string.h>
 #include <math.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include "MEM_guardedalloc.h"
 
-#include "IMB_imbuf.h"
-
-
-
-
-#include "DNA_armature_types.h"
-#include "DNA_boid_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_constraint_types.h" // for drawing constraint
-#include "DNA_effect_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_material_types.h"
-#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_meta_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_force.h"
-#include "DNA_object_fluidsim.h"
-#include "DNA_particle_types.h"
-#include "DNA_space_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
 #include "DNA_smoke_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_view3d_types.h"
 #include "DNA_world_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_rand.h"
 
 #include "BKE_anim.h"                  //for the where_on_path function
-#include "BKE_curve.h"
 #include "BKE_constraint.h" // for the get_constraint_target function
 #include "BKE_DerivedMesh.h"
 #include "BKE_deform.h"
 #include "BKE_displist.h"
-#include "BKE_effect.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
@@ -90,9 +66,6 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
-#include "BKE_property.h"
-#include "BKE_softbody.h"
-#include "BKE_smoke.h"
 #include "BKE_unit.h"
 #include "BKE_utildefines.h"
 #include "smoke_API.h"
 #include "BIF_glutil.h"
 
 #include "GPU_draw.h"
-#include "GPU_material.h"
 #include "GPU_extensions.h"
 
 #include "ED_mesh.h"
 #include "ED_screen.h"
 #include "ED_sculpt.h"
 #include "ED_types.h"
-#include "ED_util.h"
+#include "ED_curve.h" /* for ED_curve_editnurbs */
 
 #include "UI_resources.h"
-#include "UI_interface_icons.h"
 
 #include "WM_api.h"
 #include "wm_subwindow.h"
 ((vd->drawtype==OB_TEXTURE && dt>OB_SOLID) || \
        (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
-#define CHECK_OB_DRAWFACEDOT(sce, vd, dt) \
-(      (sce->toolsettings->selectmode & SCE_SELECT_FACE) && \
-       (vd->drawtype<=OB_SOLID) && \
-       (G.f & G_BACKBUFSEL)==0 && \
-       (((vd->drawtype==OB_SOLID) && (dt>=OB_SOLID) && (vd->flag2 & V3D_SOLID_TEX) && (vd->flag & V3D_ZBUF_SELECT)) == 0) \
-       )
-
 static void draw_bounding_volume(Scene *scene, Object *ob);
 
 static void drawcube_size(float size);
@@ -140,6 +104,26 @@ static void drawcircle_size(float size);
 static void draw_empty_sphere(float size);
 static void draw_empty_cone(float size);
 
+static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
+{
+       if((sce->toolsettings->selectmode & SCE_SELECT_FACE) == 0)
+               return 0;
+
+       if(G.f & G_BACKBUFSEL)
+               return 0;
+
+       if((vd->flag & V3D_ZBUF_SELECT) == 0)
+               return 1;
+
+       /* if its drawing textures with zbuf sel, then dont draw dots */
+       if(dt==OB_TEXTURE && vd->drawtype==OB_TEXTURE)
+               return 0;
+
+       if(vd->drawtype>=OB_SOLID && vd->flag2 & V3D_SOLID_TEX)
+               return 0;
+
+       return 1;
+}
 
 /* ************* only use while object drawing **************
  * or after running ED_view3d_init_mats_rv3d
@@ -157,7 +141,7 @@ static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr, int l
                        return;
        }
        
-       VECCOPY(vec4, vec);
+       copy_v3_v3(vec4, vec);
        vec4[3]= 1.0;
        
        mul_m4_v4(rv3d->persmatob, vec4);
@@ -186,7 +170,7 @@ static void view3d_project_short_noclip(ARegion *ar, float *vec, short *adr)
        
        adr[0]= IS_CLIPPED;
        
-       VECCOPY(vec4, vec);
+       copy_v3_v3(vec4, vec);
        vec4[3]= 1.0;
        
        mul_m4_v4(rv3d->persmatob, vec4);
@@ -332,26 +316,105 @@ static float cosval[32] ={
        1.00000000
 };
 
-/* flag is same as for draw_object */
-void drawaxes(float size, int flag, char drawtype)
+static void draw_xyz_wire(float *c, float size, int axis)
+{
+       float v1[3]= {0.f, 0.f, 0.f}, v2[3] = {0.f, 0.f, 0.f};
+       float dim = size * 0.1;
+       float dx[3], dy[3], dz[3];
+
+       dx[0]=dim; dx[1]=0.f; dx[2]=0.f;
+       dy[0]=0.f; dy[1]=dim; dy[2]=0.f;
+       dz[0]=0.f; dz[1]=0.f; dz[2]=dim;
+
+       switch(axis) {
+               case 0:         /* x axis */
+                       glBegin(GL_LINES);
+                       
+                       /* bottom left to top right */
+                       sub_v3_v3v3(v1, c, dx);
+                       sub_v3_v3(v1, dy);
+                       add_v3_v3v3(v2, c, dx);
+                       add_v3_v3(v2, dy);
+                       
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+                       
+                       /* top left to bottom right */
+                       mul_v3_fl(dy, 2.f);
+                       add_v3_v3(v1, dy);
+                       sub_v3_v3(v2, dy);
+                       
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+                       
+                       glEnd();
+                       break;
+               case 1:         /* y axis */
+                       glBegin(GL_LINES);
+                       
+                       /* bottom left to top right */
+                       mul_v3_fl(dx, 0.75f);
+                       sub_v3_v3v3(v1, c, dx);
+                       sub_v3_v3(v1, dy);
+                       add_v3_v3v3(v2, c, dx);
+                       add_v3_v3(v2, dy);
+                       
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+                       
+                       /* top left to center */
+                       mul_v3_fl(dy, 2.f);
+                       add_v3_v3(v1, dy);
+                       copy_v3_v3(v2, c);
+                       
+                       glVertex3fv(v1);
+                       glVertex3fv(v2);
+                       
+                       glEnd();
+                       break;
+               case 2:         /* z axis */
+                       glBegin(GL_LINE_STRIP);
+                       
+                       /* start at top left */
+                       sub_v3_v3v3(v1, c, dx);
+                       add_v3_v3v3(v1, c, dz);
+                       
+                       glVertex3fv(v1);
+                       
+                       mul_v3_fl(dx, 2.f);
+                       add_v3_v3(v1, dx);
+
+                       glVertex3fv(v1);
+                       
+                       mul_v3_fl(dz, 2.f);
+                       sub_v3_v3(v1, dx);
+                       sub_v3_v3(v1, dz);
+                       
+                       glVertex3fv(v1);
+                       
+                       add_v3_v3(v1, dx);
+               
+                       glVertex3fv(v1);
+                       
+                       glEnd();
+                       break;
+       }
+       
+}
+
+void drawaxes(float size, char drawtype)
 {
        int axis;
        float v1[3]= {0.0, 0.0, 0.0};
        float v2[3]= {0.0, 0.0, 0.0};
        float v3[3]= {0.0, 0.0, 0.0};
-
-       if(G.f & G_RENDER_SHADOW)
-               return;
        
        switch(drawtype) {
        
        case OB_PLAINAXES:
                for (axis=0; axis<3; axis++) {
-                       float v1[3]= {0.0, 0.0, 0.0};
-                       float v2[3]= {0.0, 0.0, 0.0};
-                       
                        glBegin(GL_LINES);
-
+                       
                        v1[axis]= size;
                        v2[axis]= -size;
                        glVertex3fv(v1);
@@ -378,11 +441,11 @@ void drawaxes(float size, int flag, char drawtype)
                
                for (axis=0; axis<4; axis++) {
                        if (axis % 2 == 1) {
-                               v2[0] *= -1;
-                               v3[1] *= -1;
+                               v2[0] = -v2[0];
+                               v3[1] = -v3[1];
                        } else {
-                               v2[1] *= -1;
-                               v3[0] *= -1;
+                               v2[1] = -v2[1];
+                               v3[0] = -v3[0];
                        }
                        
                        glVertex3fv(v1);
@@ -412,38 +475,28 @@ void drawaxes(float size, int flag, char drawtype)
        case OB_ARROWS:
        default:
                for (axis=0; axis<3; axis++) {
-                       float v1[3]= {0.0, 0.0, 0.0};
-                       float v2[3]= {0.0, 0.0, 0.0};
                        int arrow_axis= (axis==0)?1:0;
                        
                        glBegin(GL_LINES);
-
+                       
                        v2[axis]= size;
                        glVertex3fv(v1);
                        glVertex3fv(v2);
                                
-                       v1[axis]= size*0.8;
-                       v1[arrow_axis]= -size*0.125;
+                       v1[axis]= size*0.85;
+                       v1[arrow_axis]= -size*0.08;
                        glVertex3fv(v1);
                        glVertex3fv(v2);
                                
-                       v1[arrow_axis]= size*0.125;
+                       v1[arrow_axis]= size*0.08;
                        glVertex3fv(v1);
                        glVertex3fv(v2);
-
+                       
                        glEnd();
                                
                        v2[axis]+= size*0.125;
                        
-                       // patch for 3d cards crashing on glSelect for text drawing (IBM)
-                       if((flag & DRAW_PICKING) == 0) {
-                               if (axis==0)
-                                       view3d_cached_text_draw_add(v2[0], v2[1], v2[2], "x", 0, V3D_CACHE_TEXT_ZBUF);
-                               else if (axis==1)
-                                       view3d_cached_text_draw_add(v2[0], v2[1], v2[2], "y", 0, V3D_CACHE_TEXT_ZBUF);
-                               else
-                                       view3d_cached_text_draw_add(v2[0], v2[1], v2[2], "z", 0, V3D_CACHE_TEXT_ZBUF);
-                       }
+                       draw_xyz_wire(v2, size, axis);
                }
                break;
        }
@@ -453,12 +506,10 @@ void drawcircball(int mode, float *cent, float rad, float tmat[][4])
 {
        float vec[3], vx[3], vy[3];
        int a, tot=32;
-       
-       VECCOPY(vx, tmat[0]);
-       VECCOPY(vy, tmat[1]);
-       mul_v3_fl(vx, rad);
-       mul_v3_fl(vy, rad);
-       
+
+       mul_v3_v3fl(vx, tmat[0], rad);
+       mul_v3_v3fl(vy, tmat[1], rad);
+
        glBegin(mode);
        for(a=0; a<tot; a++) {
                vec[0]= cent[0] + *(sinval+a) * vx[0] + *(cosval+a) * vy[0];
@@ -470,12 +521,9 @@ void drawcircball(int mode, float *cent, float rad, float tmat[][4])
 }
 
 /* circle for object centers, special_color is for library or ob users */
-static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, float *vec, int selstate, int special_color)
+static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, float *co, int selstate, int special_color)
 {
-       float size;
-       
-       size= rv3d->persmat[0][3]*vec[0]+ rv3d->persmat[1][3]*vec[1]+ rv3d->persmat[2][3]*vec[2]+ rv3d->persmat[3][3];
-       size*= rv3d->pixsize*((float)U.obcenter_dia*0.5f);
+       const float size= view3d_pixel_size(rv3d, co) * (float)U.obcenter_dia * 0.5f;
 
        /* using gldepthfunc guarantees that it does write z values, but not checks for it, so centers remain visible independt order of drawing */
        if(v3d->zbuf)  glDepthFunc(GL_ALWAYS);
@@ -491,10 +539,10 @@ static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, float *vec, int se
                else if (selstate == SELECT) UI_ThemeColorShadeAlpha(TH_SELECT, 0, -80);
                else if (selstate == DESELECT) UI_ThemeColorShadeAlpha(TH_TRANSFORM, 0, -80);
        }
-       drawcircball(GL_POLYGON, vec, size, rv3d->viewinv);
+       drawcircball(GL_POLYGON, co, size, rv3d->viewinv);
        
        UI_ThemeColorShadeAlpha(TH_WIRE, 0, -30);
-       drawcircball(GL_LINE_LOOP, vec, size, rv3d->viewinv);
+       drawcircball(GL_LINE_LOOP, co, size, rv3d->viewinv);
        
        glDisable(GL_BLEND);
        if(v3d->zbuf)  glDepthFunc(GL_LEQUAL);
@@ -507,10 +555,10 @@ static int CachedTextLevel= 0;
 typedef struct ViewCachedString {
        struct ViewCachedString *next, *prev;
        float vec[3], col[4];
-       char str[128]; 
        short mval[2];
        short xoffs;
        short flag;
+       /* str is allocated past the end */
 } ViewCachedString;
 
 void view3d_cached_text_draw_begin()
@@ -520,19 +568,20 @@ void view3d_cached_text_draw_begin()
        CachedTextLevel++;
 }
 
-void view3d_cached_text_draw_add(float x, float y, float z, char *str, short xoffs, short flag)
+void view3d_cached_text_draw_add(const float co[3], const char *str, short xoffs, short flag)
 {
+       int alloc_len= strlen(str) + 1;
        ListBase *strings= &CachedText[CachedTextLevel-1];
-       ViewCachedString *vos= MEM_callocN(sizeof(ViewCachedString), "ViewCachedString");
+       ViewCachedString *vos= MEM_callocN(sizeof(ViewCachedString) + alloc_len, "ViewCachedString");
 
        BLI_addtail(strings, vos);
-       BLI_strncpy(vos->str, str, 128);
-       vos->vec[0]= x;
-       vos->vec[1]= y;
-       vos->vec[2]= z;
+       copy_v3_v3(vos->vec, co);
        glGetFloatv(GL_CURRENT_COLOR, vos->col);
        vos->xoffs= xoffs;
        vos->flag= flag;
+
+       /* allocate past the end */
+       memcpy(++vos, str, alloc_len);
 }
 
 void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, float mat[][4])
@@ -544,7 +593,7 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
        
        /* project first and test */
        for(vos= strings->first; vos; vos= vos->next) {
-               if(mat)
+               if(mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
                        mul_m4_v3(mat, vos->vec);
                view3d_project_short_clip(ar, vos->vec, vos->mval, 0);
                if(vos->mval[0]!=IS_CLIPPED)
@@ -552,14 +601,14 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
        }
 
        if(tot) {
+#if 0
                bglMats mats; /* ZBuffer depth vars */
                double ux, uy, uz;
                float depth;
 
                if(v3d->zbuf)
                        bgl_get_mats(&mats);
-
-
+#endif
                if(rv3d->rflag & RV3D_CLIPPING)
                        for(a=0; a<6; a++)
                                glDisable(GL_CLIP_PLANE0+a);
@@ -576,7 +625,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(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);
@@ -584,10 +633,16 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
                                if(uz > depth)
                                        continue;
                        }
-
+#endif
                        if(vos->mval[0]!=IS_CLIPPED) {
+                               const char *str= (char *)(vos+1);
                                glColor3fv(vos->col);
-                               BLF_draw_default((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, vos->str);
+                               if(vos->flag & V3D_CACHE_TEXT_ASCII) {
+                                       BLF_draw_default_ascii((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str, 65535); /* XXX, use real length */
+                               }
+                               else {
+                                       BLF_draw_default((float)vos->mval[0]+vos->xoffs, (float)vos->mval[1], (depth_write)? 0.0f: 2.0f, str, 65535); /* XXX, use real length */
+                               }
                        }
                }
                
@@ -695,19 +750,11 @@ static void drawshadbuflimits(Lamp *la, float mat[][4])
 {
        float sta[3], end[3], lavec[3];
 
-       lavec[0]= -mat[2][0];
-       lavec[1]= -mat[2][1];
-       lavec[2]= -mat[2][2];
+       negate_v3_v3(lavec, mat[2]);
        normalize_v3(lavec);
 
-       sta[0]= mat[3][0]+ la->clipsta*lavec[0];
-       sta[1]= mat[3][1]+ la->clipsta*lavec[1];
-       sta[2]= mat[3][2]+ la->clipsta*lavec[2];
-
-       end[0]= mat[3][0]+ la->clipend*lavec[0];
-       end[1]= mat[3][1]+ la->clipend*lavec[1];
-       end[2]= mat[3][2]+ la->clipend*lavec[2];
-
+       madd_v3_v3v3fl(sta, mat[3], lavec, la->clipsta);
+       madd_v3_v3v3fl(end, mat[3], lavec, la->clipend);
 
        glBegin(GL_LINE_STRIP);
                glVertex3fv(sta);
@@ -762,10 +809,7 @@ static void spotvolume(float *lvec, float *vvec, float inp)
        quat_to_mat3(mat1,q);
 
        /* rotate lamp vector now over acos(inp) degrees */
-
-       vvec[0] = lvec[0] ; 
-       vvec[1] = lvec[1] ; 
-       vvec[2] = lvec[2] ;
+       copy_v3_v3(vvec, lvec);
 
        unit_m3(mat2);
        co = inp;
@@ -792,25 +836,17 @@ static void spotvolume(float *lvec, float *vvec, float inp)
 
 static void draw_spot_cone(Lamp *la, float x, float z)
 {
-       float vec[3];
-
        z= fabs(z);
 
        glBegin(GL_TRIANGLE_FAN);
        glVertex3f(0.0f, 0.0f, -x);
 
        if(la->mode & LA_SQUARE) {
-               vec[0]= z;
-               vec[1]= z;
-               vec[2]= 0.0;
-
-               glVertex3fv(vec);
-               vec[1]= -z;
-               glVertex3fv(vec);
-               vec[0]= -z;
-               glVertex3fv(vec);
-               vec[1]= z;
-               glVertex3fv(vec);
+               glVertex3f(z, z, 0);
+               glVertex3f(-z, z, 0);
+               glVertex3f(-z, -z, 0);
+               glVertex3f(z, -z, 0);
+               glVertex3f(z, z, 0);
        }
        else {
                float angle;
@@ -839,7 +875,7 @@ static void draw_transp_spot_volume(Lamp *la, float x, float z)
 
        draw_spot_cone(la, x, z);
 
-       /* draw front side lightening */
+       /* draw front side lighting */
        glCullFace(GL_BACK);
 
        glBlendFunc(GL_ONE,  GL_ONE); 
@@ -858,19 +894,17 @@ static void draw_transp_spot_volume(Lamp *la, float x, float z)
 static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 {
        Object *ob= base->object;
+       const float pixsize= view3d_pixel_size(rv3d, ob->obmat[3]);
        Lamp *la= ob->data;
        float vec[3], lvec[3], vvec[3], circrad, x,y,z;
-       float pixsize, lampsize;
+       float lampsize;
        float imat[4][4], curcol[4];
        char col[4];
        int drawcone= (dt>OB_WIRE && !(G.f & G_PICKSEL) && la->type == LA_SPOT && (la->mode & LA_SHOW_CONE));
-
-       if(G.f & G_RENDER_SHADOW)
-               return;
        
        if(drawcone && !v3d->transp) {
                /* in this case we need to draw delayed */
-               add_view3d_after(v3d, base, V3D_TRANSP, flag);
+               add_view3d_after(&v3d->afterdraw_transp, base, flag);
                return;
        }
        
@@ -879,14 +913,15 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        glLoadMatrixf(rv3d->viewmat);
 
        /* lets calculate the scale: */
-       pixsize= rv3d->persmat[0][3]*ob->obmat[3][0]+ rv3d->persmat[1][3]*ob->obmat[3][1]+ rv3d->persmat[2][3]*ob->obmat[3][2]+ rv3d->persmat[3][3];
-       pixsize*= rv3d->pixsize;
        lampsize= pixsize*((float)U.obcenter_dia*0.5f);
 
        /* and view aligned matrix: */
        copy_m4_m4(imat, rv3d->viewinv);
        normalize_v3(imat[0]);
        normalize_v3(imat[1]);
+
+       /* lamp center */
+       copy_v3_v3(vec, ob->obmat[3]);
        
        /* for AA effects */
        glGetFloatv(GL_CURRENT_COLOR, curcol);
@@ -901,7 +936,6 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                }
                
                /* Inner Circle */
-               VECCOPY(vec, ob->obmat[3]);
                glEnable(GL_BLEND);
                drawcircball(GL_LINE_LOOP, vec, lampsize, imat);
                glDisable(GL_BLEND);
@@ -913,21 +947,23 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        
                /* Outer circle */
                circrad = 3.0f*lampsize;
+               setlinestyle(3);
+
                drawcircball(GL_LINE_LOOP, vec, circrad, imat);
-       }
-       else
-               circrad = 0.0f;
-       
-       setlinestyle(3);
 
-       /* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
-       if (la->type!=LA_HEMI) {
-               if ((la->mode & LA_SHAD_RAY) ||
-                       ((la->mode & LA_SHAD_BUF) && (la->type==LA_SPOT)) )
-               {
-                       drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f*pixsize, imat);
+               /* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
+               if(la->type!=LA_HEMI) {
+                       if(     (la->mode & LA_SHAD_RAY) ||
+                               ((la->mode & LA_SHAD_BUF) && (la->type==LA_SPOT))
+                       ) {
+                               drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f*pixsize, imat);
+                       }
                }
        }
+       else {
+               setlinestyle(3);
+               circrad = 0.0f;
+       }
        
        /* draw the pretty sun rays */
        if(la->type==LA_SUN) {
@@ -938,10 +974,8 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                vec_rot_to_mat3( mat,imat[2], M_PI/4.0f);
                
                /* vectors */
-               VECCOPY(v1, imat[0]);
-               mul_v3_fl(v1, circrad*1.2f);
-               VECCOPY(v2, imat[0]);
-               mul_v3_fl(v2, circrad*2.5f);
+               mul_v3_v3fl(v1, imat[0], circrad * 1.2f);
+               mul_v3_v3fl(v2, imat[0], circrad * 2.5f);
                
                /* center */
                glTranslatef(vec[0], vec[1], vec[2]);
@@ -969,7 +1003,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        }
        
        glPopMatrix();  /* back in object space */
-       vec[0]= vec[1]= vec[2]= 0.0f;
+       zero_v3(vec);
        
        if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) {  
                lvec[0]=lvec[1]= 0.0; 
@@ -1000,17 +1034,20 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                /* draw the circle/square at the end of the cone */
                glTranslatef(0.0, 0.0 ,  x);
                if(la->mode & LA_SQUARE) {
-                       vvec[0]= fabs(z);
-                       vvec[1]= fabs(z);
-                       vvec[2]= 0.0;
+                       float tvec[3];
+                       float z_abs= fabs(z);
+
+                       tvec[0]= tvec[1]= z_abs;
+                       tvec[2]= 0.0;
+
                        glBegin(GL_LINE_LOOP);
-                               glVertex3fv(vvec);
-                               vvec[1]= -fabs(z);
-                               glVertex3fv(vvec);
-                               vvec[0]= -fabs(z);
-                               glVertex3fv(vvec);
-                               vvec[1]= fabs(z);
-                               glVertex3fv(vvec);
+                               glVertex3fv(tvec);
+                               tvec[1]= -z_abs; /* neg */
+                               glVertex3fv(tvec);
+                               tvec[0]= -z_abs; /* neg */
+                               glVertex3fv(tvec);
+                               tvec[1]= z_abs; /* pos */
+                               glVertex3fv(tvec);
                        glEnd();
                }
                else circ(0.0, 0.0, fabs(z));
@@ -1027,6 +1064,22 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
                if(drawcone)
                        draw_transp_spot_volume(la, x, z);
+
+               /* draw clip start, useful for wide cones where its not obvious where the start is */
+               glTranslatef(0.0, 0.0 , -x); /* reverse translation above */
+               if(la->type==LA_SPOT && (la->mode & LA_SHAD_BUF) ) {
+                       float lvec_clip[3];
+                       float vvec_clip[3];
+                       float clipsta_fac= la->clipsta / -x;
+
+                       interp_v3_v3v3(lvec_clip, vec, lvec, clipsta_fac);
+                       interp_v3_v3v3(vvec_clip, vec, vvec, clipsta_fac);
+
+                       glBegin(GL_LINE_STRIP);
+                               glVertex3fv(lvec_clip);
+                               glVertex3fv(vvec_clip);
+                       glEnd();
+               }
        }
        else if ELEM(la->type, LA_HEMI, LA_SUN) {
                
@@ -1042,7 +1095,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        /* draw the hemisphere curves */
                        short axis, steps, dir;
                        float outdist, zdist, mul;
-                       vec[0]=vec[1]=vec[2]= 0.0;
+                       zero_v3(vec);
                        outdist = 0.14; mul = 1.4; dir = 1;
                        
                        setlinestyle(4);
@@ -1091,7 +1144,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        
        /* and back to viewspace */
        glLoadMatrixf(rv3d->viewmat);
-       VECCOPY(vec, ob->obmat[3]);
+       copy_v3_v3(vec, ob->obmat[3]);
 
        setlinestyle(0);
        
@@ -1160,48 +1213,71 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
 {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
-       World *wrld;
-       float nobmat[4][4], vec[8][4], fac, facx, facy, depth;
+       float vec[8][4], facx, facy, depth, aspx, aspy, caspx, caspy, shx, shy;
        int i;
+       float drawsize;
+       const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
 
-       if(G.f & G_RENDER_SHADOW)
-               return;
-
+       const float scax= 1.0f / len_v3(ob->obmat[0]);
+       const float scay= 1.0f / len_v3(ob->obmat[1]);
+       const float scaz= 1.0f / len_v3(ob->obmat[2]);
+       
        cam= ob->data;
+       aspx= (float) scene->r.xsch*scene->r.xasp;
+       aspy= (float) scene->r.ysch*scene->r.yasp;
+
+       if(aspx < aspy) {
+               caspx= aspx / aspy;
+               caspy= 1.0;
+       }
+       else {
+               caspx= 1.0;
+               caspy= aspy / aspx;
+       }
        
        glDisable(GL_LIGHTING);
        glDisable(GL_CULL_FACE);
        
-       if(rv3d->persp>=2 && cam->type==CAM_ORTHO && ob==v3d->camera) {
-               facx= 0.5*cam->ortho_scale*1.28;
-               facy= 0.5*cam->ortho_scale*1.024;
-               depth= -cam->clipsta-0.1;
+       if(cam->type==CAM_ORTHO) {
+               facx= 0.5f * cam->ortho_scale * caspx * scax;
+               facy= 0.5f * cam->ortho_scale * caspy * scay;
+               shx= cam->shiftx * cam->ortho_scale * scax;
+               shy= cam->shifty * cam->ortho_scale * scay;
+               depth= is_view ? -((cam->clipsta * scaz) + 0.1f) : - cam->drawsize * cam->ortho_scale * scaz;
+               
+               drawsize= 0.5f * cam->ortho_scale;
        }
        else {
-               fac= cam->drawsize;
-               if(rv3d->persp>=2 && ob==v3d->camera) fac= cam->clipsta+0.1; /* that way it's always visible */
+               /* that way it's always visible - clipsta+0.1 */
+               float fac;
+               drawsize= cam->drawsize / ((scax + scay + scaz) / 3.0f);
+               fac= is_view ? (cam->clipsta + 0.1f) : drawsize;
+               depth= - fac*cam->lens/16.0 * scaz;
+               facx= fac * caspx * scax;
+               facy= fac * caspy * scay;
+               shx= cam->shiftx*fac*2 * scax;
+               shy= cam->shifty*fac*2 * scay;
                
-               depth= - fac*cam->lens/16.0;
-               facx= fac*1.28;
-               facy= fac*1.024;
        }
        
-       vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.001;       /* GLBUG: for picking at iris Entry (well thats old!) */
-       vec[1][0]= facx; vec[1][1]= facy; vec[1][2]= depth;
-       vec[2][0]= facx; vec[2][1]= -facy; vec[2][2]= depth;
-       vec[3][0]= -facx; vec[3][1]= -facy; vec[3][2]= depth;
-       vec[4][0]= -facx; vec[4][1]= facy; vec[4][2]= depth;
+       vec[0][0]= 0.0; vec[0][1]= 0.0; vec[0][2]= 0.0;
+       vec[1][0]= shx + facx; vec[1][1]= shy + facy; vec[1][2]= depth;
+       vec[2][0]= shx + facx; vec[2][1]= shy - facy; vec[2][2]= depth;
+       vec[3][0]= shx - facx; vec[3][1]= shy - facy; vec[3][2]= depth;
+       vec[4][0]= shx - facx; vec[4][1]= shy + facy; vec[4][2]= depth;
 
+       /* camera frame */
        glBegin(GL_LINE_LOOP);
                glVertex3fv(vec[1]); 
                glVertex3fv(vec[2]); 
                glVertex3fv(vec[3]); 
                glVertex3fv(vec[4]);
        glEnd();
-       
 
-       if(rv3d->persp>=2 && ob==v3d->camera) return;
-       
+       if(is_view)
+               return;
+
+       /* center point to camera frame */
        glBegin(GL_LINE_STRIP);
                glVertex3fv(vec[2]); 
                glVertex3fv(vec[0]);
@@ -1215,7 +1291,7 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
        /* arrow on top */
        vec[0][2]= depth;
 
-       
+
        /* draw an outline arrow for inactive cameras and filled
         * for active cameras. We actually draw both outline+filled
         * for active cameras so the wire can be seen side-on */        
@@ -1223,24 +1299,26 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob
                if (i==0) glBegin(GL_LINE_LOOP);
                else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
                else break;
+
+               vec[0][0]= shx + ((-0.7 * drawsize) * scax);
+               vec[0][1]= shy + ((drawsize * (caspy + 0.1)) * scay);
+               glVertex3fv(vec[0]); /* left */
                
-               vec[0][0]= -0.7*cam->drawsize;
-               vec[0][1]= 1.1*cam->drawsize;
-               glVertex3fv(vec[0]);
-               
-               vec[0][0]= 0.0; 
-               vec[0][1]= 1.8*cam->drawsize;
-               glVertex3fv(vec[0]);
+               vec[0][0]= shx + ((0.7 * drawsize) * scax);
+               glVertex3fv(vec[0]); /* right */
                
-               vec[0][0]= 0.7*cam->drawsize; 
-               vec[0][1]= 1.1*cam->drawsize;
-               glVertex3fv(vec[0]);
+               vec[0][0]= shx;
+               vec[0][1]= shy + ((1.1 * drawsize * (caspy + 0.7)) * scay);
+               glVertex3fv(vec[0]); /* top */
        
                glEnd();
        }
 
        if(flag==0) {
                if(cam->flag & (CAM_SHOWLIMITS+CAM_SHOWMIST)) {
+                       float nobmat[4][4];
+                       World *wrld;
+       
                        /* draw in normalized object matrix space */
                        copy_m4_m4(nobmat, ob->obmat);
                        normalize_m4(nobmat);
@@ -1299,10 +1377,10 @@ void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPo
 {
        Object *obedit= vc->obedit;
        Lattice *lt= obedit->data;
-       BPoint *bp = lt->editlatt->def;
+       BPoint *bp = lt->editlatt->latt->def;
        DispList *dl = find_displist(&obedit->disp, DL_VERTS);
        float *co = dl?dl->verts:NULL;
-       int i, N = lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
+       int i, N = lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
        short s[2] = {IS_CLIPPED, 0};
 
        ED_view3d_local_clipping(vc->rv3d, obedit->obmat); /* for local clipping lookups */
@@ -1342,14 +1420,16 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
        Lattice *lt= ob->data;
        DispList *dl;
        int u, v, w;
-       int use_wcol= 0;
+       int use_wcol= 0, is_edit= (lt->editlatt != NULL);
 
        /* now we default make displist, this will modifiers work for non animated case */
        if(ob->disp.first==NULL)
                lattice_calc_modifiers(scene, ob);
        dl= find_displist(&ob->disp, DL_VERTS);
        
-       if(lt->editlatt) {
+       if(is_edit) {
+               lt= lt->editlatt->latt;
+
                cpack(0x004000);
                
                if(ob->defbase.first && lt->dvert) {
@@ -1358,8 +1438,6 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
                }
        }
        
-       if(lt->editlatt) lt= lt->editlatt;
-       
        glBegin(GL_LINES);
        for(w=0; w<lt->pntsw; w++) {
                int wxt = (w==0 || w==lt->pntsw-1);
@@ -1389,7 +1467,7 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
        if(use_wcol)
                glShadeModel(GL_FLAT);
 
-       if( ((Lattice *)ob->data)->editlatt ) {
+       if(is_edit) {
                if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
                
                lattice_draw_verts(lt, dl, 0);
@@ -1405,7 +1483,7 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
  * if not, ED_view3d_init_mats_rv3d() can be used for selection tools
  * but would not give correct results with dupli's for eg. which dont
  * use the object matrix in the useual way */
-static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
        struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
        EditVert *eve = EM_get_vert_for_index(index);
@@ -1489,7 +1567,7 @@ void mesh_foreachScreenEdge(ViewContext *vc, void (*func)(void *userData, EditEd
        dm->release(dm);
 }
 
-static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *cent, float *no)
+static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *cent, float *UNUSED(no))
 {
        struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ViewContext vc; } *data = userData;
        EditFace *efa = EM_get_face_for_index(index);
@@ -1527,10 +1605,11 @@ void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb
        short s[2] = {IS_CLIPPED, 0};
        Nurb *nu;
        int i;
+       ListBase *nurbs= ED_curve_editnurbs(cu);
 
        ED_view3d_local_clipping(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
 
-       for (nu= cu->editnurb->first; nu; nu=nu->next) {
+       for (nu= nurbs->first; nu; nu=nu->next) {
                if(nu->type == CU_BEZIER) {
                        for (i=0; i<nu->pntsu; i++) {
                                BezTriple *bezt = &nu->bezt[i];
@@ -1599,7 +1678,7 @@ static void draw_dm_face_normals(Scene *scene, DerivedMesh *dm)
        glEnd();
 }
 
-static void draw_dm_face_centers__mapFunc(void *userData, int index, float *cent, float *no)
+static void draw_dm_face_centers__mapFunc(void *userData, int index, float *cent, float *UNUSED(no))
 {
        EditFace *efa = EM_get_face_for_index(index);
        int sel = *((int*) userData);
@@ -1643,7 +1722,7 @@ static void draw_dm_vert_normals(Scene *scene, DerivedMesh *dm)
 }
 
        /* Draw verts with color set based on selection */
-static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
        struct { int sel; EditVert *eve_act; } * data = userData;
        EditVert *eve = EM_get_vert_for_index(index);
@@ -1720,7 +1799,7 @@ static void draw_dm_edges_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned
 }
 
        /* Draw edges */
-static int draw_dm_edges__setDrawOptions(void *userData, int index)
+static int draw_dm_edges__setDrawOptions(void *UNUSED(userData), int index)
 {
        return EM_get_edge_for_index(index)->h==0;
 }
@@ -1730,7 +1809,7 @@ static void draw_dm_edges(DerivedMesh *dm)
 }
 
        /* Draw edges with color interpolated based on selection */
-static int draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index)
+static int draw_dm_edges_sel_interp__setDrawOptions(void *UNUSED(userData), int index)
 {
        return EM_get_edge_for_index(index)->h==0;
 }
@@ -1749,13 +1828,14 @@ static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int i
 
 static void draw_dm_edges_sel_interp(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol)
 {
-       unsigned char *cols[2] = {baseCol, selCol};
-
+       unsigned char *cols[2];
+       cols[0]= baseCol;
+       cols[1]= selCol;
        dm->drawMappedEdgesInterp(dm, draw_dm_edges_sel_interp__setDrawOptions, draw_dm_edges_sel_interp__setDrawInterpOptions, cols);
 }
 
        /* Draw only seam edges */
-static int draw_dm_edges_seams__setDrawOptions(void *userData, int index)
+static int draw_dm_edges_seams__setDrawOptions(void *UNUSED(userData), int index)
 {
        EditEdge *eed = EM_get_edge_for_index(index);
 
@@ -1767,7 +1847,7 @@ static void draw_dm_edges_seams(DerivedMesh *dm)
 }
 
        /* Draw only sharp edges */
-static int draw_dm_edges_sharp__setDrawOptions(void *userData, int index)
+static int draw_dm_edges_sharp__setDrawOptions(void *UNUSED(userData), int index)
 {
        EditEdge *eed = EM_get_edge_for_index(index);
 
@@ -1781,7 +1861,7 @@ static void draw_dm_edges_sharp(DerivedMesh *dm)
 
        /* 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 *drawSmooth_r)
+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;
        EditFace *efa = EM_get_face_for_index(index);
@@ -1810,15 +1890,15 @@ static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned
        data.cols[2] = actCol;
        data.efa_act = efa_act;
 
-       dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, &data, 0);
+       dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, &data, 0, GPU_enable_material);
 }
 
-static int draw_dm_creases__setDrawOptions(void *userData, int index)
+static int draw_dm_creases__setDrawOptions(void *UNUSED(userData), int index)
 {
        EditEdge *eed = EM_get_edge_for_index(index);
 
        if (eed->h==0 && eed->crease!=0.0) {
-               UI_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, eed->crease);
+               UI_ThemeColorBlend(TH_WIRE, TH_EDGE_CREASE, eed->crease);
                return 1;
        } else {
                return 0;
@@ -1831,7 +1911,7 @@ static void draw_dm_creases(DerivedMesh *dm)
        glLineWidth(1.0);
 }
 
-static int draw_dm_bweights__setDrawOptions(void *userData, int index)
+static int draw_dm_bweights__setDrawOptions(void *UNUSED(userData), int index)
 {
        EditEdge *eed = EM_get_edge_for_index(index);
 
@@ -1842,7 +1922,7 @@ static int draw_dm_bweights__setDrawOptions(void *userData, int index)
                return 0;
        }
 }
-static void draw_dm_bweights__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+static void draw_dm_bweights__mapFunc(void *UNUSED(userData), int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
        EditVert *eve = EM_get_vert_for_index(index);
 
@@ -1877,7 +1957,7 @@ static void draw_dm_bweights(Scene *scene, DerivedMesh *dm)
 
 /* EditMesh drawing routines*/
 
-static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit, EditMesh *em, DerivedMesh *cageDM, EditVert *eve_act)
+static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit, DerivedMesh *cageDM, EditVert *eve_act)
 {
        ToolSettings *ts= scene->toolsettings;
        int sel;
@@ -1917,7 +1997,7 @@ static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit, EditM
                                draw_dm_verts(cageDM, sel, eve_act);
                        }
                        
-                       if( CHECK_OB_DRAWFACEDOT(scene, v3d, obedit->dt) ) {
+                       if(check_ob_drawface_dot(scene, v3d, obedit->dt)) {
                                glPointSize(fsize);
                                glColor4ubv((GLubyte *)fcol);
                                draw_dm_face_centers(cageDM, sel);
@@ -1997,14 +2077,17 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
        Mesh *me= ob->data;
        EditEdge *eed;
        EditFace *efa;
-       float v1[3], v2[3], v3[3], v4[3], x, y, z;
+       float v1[3], v2[3], v3[3], v4[3], vmid[3];
        float fvec[3];
        char val[32]; /* Stores the measurement display text here */
        char conv_float[5]; /* Use a float conversion matching the grid size */
        float area, col[3]; /* area of the face,  color of the text to draw */
        float grid= unit->system ? unit->scale_length : v3d->grid;
-       int do_split= unit->flag & USER_UNIT_OPT_SPLIT;
-       if(G.f & (G_RENDER_OGL|G_RENDER_SHADOW))
+       const int do_split= unit->flag & USER_UNIT_OPT_SPLIT;
+       const int do_global= v3d->flag & V3D_GLOBAL_STATS;
+       const int do_moving= G.moving;
+
+       if(v3d->flag2 & V3D_RENDER_OVERRIDE)
                return;
 
        /* make the precision of the pronted value proportionate to the gridsize */
@@ -2035,24 +2118,22 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                
                for(eed= em->edges.first; eed; eed= eed->next) {
                        /* draw non fgon edges, or selected edges, or edges next to selected verts while draging */
-                       if((eed->h != EM_FGON) && ((eed->f & SELECT) || (G.moving && ((eed->v1->f & SELECT) || (eed->v2->f & SELECT)) ))) {
-                               VECCOPY(v1, eed->v1->co);
-                               VECCOPY(v2, eed->v2->co);
-                               
-                               x= 0.5f*(v1[0]+v2[0]);
-                               y= 0.5f*(v1[1]+v2[1]);
-                               z= 0.5f*(v1[2]+v2[2]);
-                               
-                               if(v3d->flag & V3D_GLOBAL_STATS) {
-                                       mul_m4_v3(ob->obmat, v1);
-                                       mul_m4_v3(ob->obmat, v2);
+                       if((eed->h != EM_FGON) && ((eed->f & SELECT) || (do_moving && ((eed->v1->f & SELECT) || (eed->v2->f & SELECT)) ))) {
+                               copy_v3_v3(v1, eed->v1->co);
+                               copy_v3_v3(v2, eed->v2->co);
+
+                               interp_v3_v3v3(vmid, v1, v2, 0.5f);
+
+                               if(do_global) {
+                                       mul_mat3_m4_v3(ob->obmat, v1);
+                                       mul_mat3_m4_v3(ob->obmat, v2);
                                }
                                if(unit->system)
                                        bUnit_AsString(val, sizeof(val), len_v3v3(v1, v2)*unit->scale_length, 3, unit->system, B_UNIT_LENGTH, do_split, FALSE);
                                else
                                        sprintf(val, conv_float, len_v3v3(v1, v2));
                                
-                               view3d_cached_text_draw_add(x, y, z, val, 0, 0);
+                               view3d_cached_text_draw_add(vmid, val, 0, V3D_CACHE_TEXT_ASCII);
                        }
                }
        }
@@ -2067,18 +2148,18 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                glColor3fv(col);
                
                for(efa= em->faces.first; efa; efa= efa->next) {
-                       if((efa->f & SELECT)) { // XXX || (G.moving && faceselectedOR(efa, SELECT)) ) {
-                               VECCOPY(v1, efa->v1->co);
-                               VECCOPY(v2, efa->v2->co);
-                               VECCOPY(v3, efa->v3->co);
+                       if((efa->f & SELECT)) { // XXX || (do_moving && faceselectedOR(efa, SELECT)) ) {
+                               copy_v3_v3(v1, efa->v1->co);
+                               copy_v3_v3(v2, efa->v2->co);
+                               copy_v3_v3(v3, efa->v3->co);
                                if (efa->v4) {
-                                       VECCOPY(v4, efa->v4->co);
+                                       copy_v3_v3(v4, efa->v4->co);
                                }
-                               if(v3d->flag & V3D_GLOBAL_STATS) {
-                                       mul_m4_v3(ob->obmat, v1);
-                                       mul_m4_v3(ob->obmat, v2);
-                                       mul_m4_v3(ob->obmat, v3);
-                                       if (efa->v4) mul_m4_v3(ob->obmat, v4);
+                               if(do_global) {
+                                       mul_mat3_m4_v3(ob->obmat, v1);
+                                       mul_mat3_m4_v3(ob->obmat, v2);
+                                       mul_mat3_m4_v3(ob->obmat, v3);
+                                       if (efa->v4) mul_mat3_m4_v3(ob->obmat, v4);
                                }
                                
                                if (efa->v4)
@@ -2091,7 +2172,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                                else
                                        sprintf(val, conv_float, area);
 
-                               view3d_cached_text_draw_add(efa->cent[0], efa->cent[1], efa->cent[2], val, 0, 0);
+                               view3d_cached_text_draw_add(efa->cent, val, 0, V3D_CACHE_TEXT_ASCII);
                        }
                }
        }
@@ -2106,20 +2187,20 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                glColor3fv(col);
                
                for(efa= em->faces.first; efa; efa= efa->next) {
-                       VECCOPY(v1, efa->v1->co);
-                       VECCOPY(v2, efa->v2->co);
-                       VECCOPY(v3, efa->v3->co);
+                       copy_v3_v3(v1, efa->v1->co);
+                       copy_v3_v3(v2, efa->v2->co);
+                       copy_v3_v3(v3, efa->v3->co);
                        if(efa->v4) {
-                               VECCOPY(v4, efa->v4->co); 
+                               copy_v3_v3(v4, efa->v4->co); 
                        }
                        else {
-                               VECCOPY(v4, v3);
+                               copy_v3_v3(v4, v3);
                        }
-                       if(v3d->flag & V3D_GLOBAL_STATS) {
-                               mul_m4_v3(ob->obmat, v1);
-                               mul_m4_v3(ob->obmat, v2);
-                               mul_m4_v3(ob->obmat, v3);
-                               mul_m4_v3(ob->obmat, v4);
+                       if(do_global) {
+                               mul_mat3_m4_v3(ob->obmat, v1);
+                               mul_mat3_m4_v3(ob->obmat, v2);
+                               mul_mat3_m4_v3(ob->obmat, v3);
+                               mul_mat3_m4_v3(ob->obmat, v4); /* intentionally executed even for tri's */
                        }
                        
                        e1= efa->e1;
@@ -2129,33 +2210,33 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                        
                        /* Calculate the angles */
                                
-                       if( (e4->f & e1->f & SELECT) || (G.moving && (efa->v1->f & SELECT)) ) {
+                       if( (e4->f & e1->f & SELECT) || (do_moving && (efa->v1->f & SELECT)) ) {
                                /* Vec 1 */
                                sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v4, v1, v2)));
                                interp_v3_v3v3(fvec, efa->cent, efa->v1->co, 0.8f);
-                               view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0, 0);
+                               view3d_cached_text_draw_add(fvec, val, 0, V3D_CACHE_TEXT_ASCII);
                        }
-                       if( (e1->f & e2->f & SELECT) || (G.moving && (efa->v2->f & SELECT)) ) {
+                       if( (e1->f & e2->f & SELECT) || (do_moving && (efa->v2->f & SELECT)) ) {
                                /* Vec 2 */
                                sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v1, v2, v3)));
                                interp_v3_v3v3(fvec, efa->cent, efa->v2->co, 0.8f);
-                               view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0, 0);
+                               view3d_cached_text_draw_add(fvec, val, 0, V3D_CACHE_TEXT_ASCII);
                        }
-                       if( (e2->f & e3->f & SELECT) || (G.moving && (efa->v3->f & SELECT)) ) {
+                       if( (e2->f & e3->f & SELECT) || (do_moving && (efa->v3->f & SELECT)) ) {
                                /* Vec 3 */
                                if(efa->v4) 
                                        sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v2, v3, v4)));
                                else
                                        sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v2, v3, v1)));
                                interp_v3_v3v3(fvec, efa->cent, efa->v3->co, 0.8f);
-                               view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0, 0);
+                               view3d_cached_text_draw_add(fvec, val, 0, V3D_CACHE_TEXT_ASCII);
                        }
                                /* Vec 4 */
                        if(efa->v4) {
-                               if( (e3->f & e4->f & SELECT) || (G.moving && (efa->v4->f & SELECT)) ) {
+                               if( (e3->f & e4->f & SELECT) || (do_moving && (efa->v4->f & SELECT)) ) {
                                        sprintf(val,"%.3f", RAD2DEG(angle_v3v3v3(v3, v4, v1)));
                                        interp_v3_v3v3(fvec, efa->cent, efa->v4->co, 0.8f);
-                                       view3d_cached_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0, 0);
+                                       view3d_cached_text_draw_add(fvec, val, 0, V3D_CACHE_TEXT_ASCII);
                                }
                        }
                }
@@ -2167,7 +2248,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
        }
 }
 
-static int draw_em_fancy__setFaceOpts(void *userData, int index, int *drawSmooth_r)
+static int draw_em_fancy__setFaceOpts(void *UNUSED(userData), int index, int *UNUSED(drawSmooth_r))
 {
        EditFace *efa = EM_get_face_for_index(index);
 
@@ -2179,7 +2260,7 @@ static int draw_em_fancy__setFaceOpts(void *userData, int index, int *drawSmooth
                return 0;
 }
 
-static int draw_em_fancy__setGLSLFaceOpts(void *userData, int index)
+static int draw_em_fancy__setGLSLFaceOpts(void *UNUSED(userData), int index)
 {
        EditFace *efa = EM_get_face_for_index(index);
 
@@ -2229,7 +2310,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                        glEnable(GL_LIGHTING);
                        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
-                       finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, 0, 0);
+                       finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, 0, 0, GPU_enable_material);
 
                        glFrontFace(GL_CCW);
                        glDisable(GL_LIGHTING);
@@ -2245,11 +2326,11 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
        else {
                if (cageDM!=finalDM) {
                        UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.7);
-                       finalDM->drawEdges(finalDM, 1);
+                       finalDM->drawEdges(finalDM, 1, 0);
                }
        }
        
-       if((me->drawflag & (ME_DRAWFACES)) || paint_facesel_test(ob)) { /* transp faces */
+       if(me->drawflag & ME_DRAWFACES) {       /* transp faces */
                unsigned char col1[4], col2[4], col3[4];
                        
                UI_GetThemeColor4ubv(TH_FACE, (char *)col1);
@@ -2325,7 +2406,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
        if(em) {
 // XXX         retopo_matrix_update(v3d);
 
-               draw_em_fancy_verts(scene, v3d, ob, em, cageDM, eve_act);
+               draw_em_fancy_verts(scene, v3d, ob, cageDM, eve_act);
 
                if(me->drawflag & ME_DRAWNORMALS) {
                        UI_ThemeColor(TH_NORMAL);
@@ -2367,7 +2448,7 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
                        GPU_disable_material();
                }
                else {
-                       dm->drawEdges(dm, 0);
+                       dm->drawEdges(dm, 0, 1);
                }
                                        
                glLineWidth(1.0);
@@ -2375,7 +2456,7 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
        }
 }
 
-static int wpaint__setSolidDrawOptions(void *userData, int index, int *drawSmooth_r)
+static int wpaint__setSolidDrawOptions(void *UNUSED(userData), int UNUSED(index), int *drawSmooth_r)
 {
        *drawSmooth_r = 1;
        return 1;
@@ -2386,7 +2467,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        Object *ob= base->object;
        Mesh *me = ob->data;
        Material *ma= give_current_material(ob, 1);
-       int hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
+       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;
        int totvert, totedge, totface;
        DispList *dl;
@@ -2408,10 +2490,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                // Unwanted combination.
-       if (ob==OBACT && paint_facesel_test(ob)) draw_wire = 0;
+       if (is_paint_sel) draw_wire = 0;
 
        if(dt==OB_BOUNDBOX) {
-               draw_bounding_volume(scene, ob);
+               if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
+                       draw_bounding_volume(scene, ob);
        }
        else if(hasHaloMat || (totface==0 && totedge==0)) {
                glPointSize(1.5);
@@ -2421,12 +2504,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        else if(dt==OB_WIRE || totface==0) {
                draw_wire = 1; /* draw wire only, no depth buffer stuff  */
        }
-       else if(        (ob==OBACT && (ob->mode & OB_MODE_TEXTURE_PAINT || paint_facesel_test(ob))) ||
+       else if(        (is_paint_sel || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
                                CHECK_OB_DRAWTEXTURE(v3d, dt))
        {
-               int faceselect= (ob==OBACT && paint_facesel_test(ob));
-
-               if ((v3d->flag&V3D_SELECT_OUTLINE) && (base->flag&SELECT) && !(G.f&G_PICKSEL || paint_facesel_test(ob)) && !draw_wire) {
+               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || is_paint_sel) && !draw_wire) {
                        draw_mesh_object_outline(v3d, ob, dm);
                }
 
@@ -2441,16 +2522,17 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glFrontFace(GL_CCW);
                }
                else {
-                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, faceselect);
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, is_paint_sel);
                }
 
-               if(!faceselect) {
+               if(!is_paint_sel) {
                        if(base->flag & SELECT)
                                UI_ThemeColor((ob==OBACT)?TH_ACTIVE:TH_SELECT);
                        else
                                UI_ThemeColor(TH_WIRE);
 
-                       dm->drawLooseEdges(dm);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
+                               dm->drawLooseEdges(dm);
                }
        }
        else if(dt==OB_SOLID) {
@@ -2458,30 +2540,31 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        /* weight paint in solid mode, special case. focus on making the weights clear
                         * rather then the shading, this is also forced in wire view */
                        GPU_enable_material(0, NULL);
-                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me->mface, 1);
-
+                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me->mface, 1, GPU_enable_material);
+               
                        bglPolygonOffset(rv3d->dist, 1.0);
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
 
                        glEnable(GL_BLEND);
-                       glColor4ub(196, 196, 196, 196);
+                       glColor4ub(255, 255, 255, 96);
                        glEnable(GL_LINE_STIPPLE);
-                       glLineStipple(1, 0x8888);
+                       glLineStipple(1, 0xAAAA);
 
-                       dm->drawEdges(dm, 1);
+                       dm->drawEdges(dm, 1, 1);
 
                        bglPolygonOffset(rv3d->dist, 0.0);
                        glDepthMask(1);
                        glDisable(GL_LINE_STIPPLE);
 
                        GPU_disable_material();
-
-
+                       
+                       /* since we already draw wire as wp guide, dont draw over the top */
+                       draw_wire= 0;
                }
                else {
                        Paint *p;
 
-                       if((v3d->flag&V3D_SELECT_OUTLINE) && (base->flag&SELECT) && !draw_wire && !ob->sculpt)
+                       if((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !draw_wire && !ob->sculpt)
                                draw_mesh_object_outline(v3d, ob, dm);
 
                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED );
@@ -2495,9 +2578,11 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                                int fast= (p->flags & PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
 
                                if(ob->sculpt->partial_redraw) {
-                                       sculpt_get_redraw_planes(planes, ar, rv3d, ob);
-                                       fpl = planes;
-                                       ob->sculpt->partial_redraw = 0;
+                                       if(ar->do_draw & RGN_DRAW_PARTIAL) {
+                                               sculpt_get_redraw_planes(planes, ar, rv3d, ob);
+                                               fpl = planes;
+                                               ob->sculpt->partial_redraw = 0;
+                                       }
                                }
 
                                dm->drawFacesSolid(dm, fpl, fast, GPU_enable_material);
@@ -2515,7 +2600,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        } else {
                                UI_ThemeColor(TH_WIRE);
                        }
-                       if(!ob->sculpt)
+                       if(!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
                                dm->drawLooseEdges(dm);
                }
        }
@@ -2538,7 +2623,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                                glEnable(GL_LIGHTING);
                                glEnable(GL_COLOR_MATERIAL);
 
-                               dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me->mface, 1);
+                               dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me->mface, 1, GPU_enable_material);
                                glDisable(GL_COLOR_MATERIAL);
                                glDisable(GL_LIGHTING);
 
@@ -2546,10 +2631,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        }
                        else if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_TEXTURE_PAINT)) {
                                if(me->mcol)
-                                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, NULL, 1);
+                                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, NULL, 1, GPU_enable_material);
                                else {
                                        glColor3f(1.0f, 1.0f, 1.0f);
-                                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, NULL, 0);
+                                       dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, NULL, 0, GPU_enable_material);
                                }
                        }
                        else do_draw= 1;
@@ -2565,7 +2650,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                                dm= mesh_get_derived_final(scene, ob, v3d->customdata_mask);
                        }
 
-                       if ((v3d->flag&V3D_SELECT_OUTLINE) && (base->flag&SELECT) && !draw_wire) {
+                       if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !draw_wire) {
                                draw_mesh_object_outline(v3d, ob, dm);
                        }
 
@@ -2582,7 +2667,8 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        } else {
                                UI_ThemeColor(TH_WIRE);
                        }
-                       dm->drawLooseEdges(dm);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
+                               dm->drawLooseEdges(dm);
                }
        }
        
@@ -2636,8 +2722,9 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glDepthMask(0); // disable write in zbuffer, selected edge wires show better
                }
                
-               dm->drawEdges(dm, (dt==OB_WIRE || totface==0));
-               
+               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) {
                        glDepthMask(1);
                        bglPolygonOffset(rv3d->dist, 0.0);
@@ -2657,7 +2744,8 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha;
        
        if(obedit && ob!=obedit && ob->data==obedit->data) {
-               if(ob_get_key(ob));
+               if(ob_get_key(ob) || ob_get_key(obedit));
+               else if(ob->modifiers.first || obedit->modifiers.first);
                else drawlinked= 1;
        }
        
@@ -2703,7 +2791,20 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        }
        
        /* GPU_begin_object_materials checked if this is needed */
-       if(do_alpha_pass) add_view3d_after(v3d, base, V3D_TRANSP, flag);
+       if(do_alpha_pass) {
+               if(ob->dtx & OB_DRAWXRAY) {
+                       add_view3d_after(&v3d->afterdraw_xraytransp, base, flag);
+               }
+               else {
+                       add_view3d_after(&v3d->afterdraw_transp, base, flag);
+               }
+       }
+       else if(ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
+               /* special case xray+transp when alpha is 1.0, without this the object vanishes */
+               if(v3d->xray == 0 && v3d->transp == 0) {
+                       add_view3d_after(&v3d->afterdraw_xray, base, flag);
+               }
+       }
        
        return retval;
 }
@@ -2854,8 +2955,7 @@ static void drawDispListsolid(ListBase *lb, Object *ob, int glsl)
                case DL_POLY:
                        if(ob->type==OB_SURF) {
                                int nr;
-                               
-                               UI_ThemeColor(TH_WIRE);
+
                                glDisable(GL_LIGHTING);
                                
                                /* for some reason glDrawArrays crashes here in half of the platforms (not osx) */
@@ -2977,6 +3077,44 @@ static void drawDispListshaded(ListBase *lb, Object *ob)
        glDisableClientState(GL_COLOR_ARRAY);
 }
 
+static void drawCurveDMWired(Object *ob)
+{
+       DerivedMesh *dm = ob->derivedFinal;
+       dm->drawEdges (dm, 1, 0);
+}
+
+/* return 1 when nothing was drawn */
+static int drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
+{
+       Object *ob= base->object;
+       DerivedMesh *dm = ob->derivedFinal;
+
+       if (!dm) {
+               return 1;
+       }
+
+       if(dt>OB_WIRE && dm->getNumFaces(dm)) {
+               int glsl = draw_glsl_material(scene, ob, v3d, dt);
+               GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
+
+               if(!glsl) {
+                       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
+                       glEnable(GL_LIGHTING);
+                       dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
+                       glDisable(GL_LIGHTING);
+               }
+               else
+                       dm->drawFacesGLSL(dm, GPU_enable_material);
+
+               GPU_end_object_materials();
+       } else {
+               if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_SOLID)==0)
+                       drawCurveDMWired (ob);
+       }
+
+       return 0;
+}
+
 /* returns 1 when nothing was drawn */
 static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt)
 {
@@ -2988,6 +3126,10 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
        
        solid= (dt > OB_WIRE);
 
+       if (drawCurveDerivedMesh(scene, v3d, rv3d, base, dt) == 0) {
+               return 0;
+       }
+
        switch(ob->type) {
        case OB_FONT:
        case OB_CURVE:
@@ -2999,7 +3141,7 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                        dl= lb->first;
                        if(dl==NULL) return 1;
 
-                       if(dl->nors==0) addnormalsDispList(ob, lb);
+                       if(dl->nors==0) addnormalsDispList(lb);
                        index3_nors_incr= 0;
                        
                        if( displist_has_faces(lb)==0) {
@@ -3046,7 +3188,7 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                        dl= lb->first;
                        if(dl==NULL) return 1;
                        
-                       if(dl->nors==NULL) addnormalsDispList(ob, lb);
+                       if(dl->nors==NULL) addnormalsDispList(lb);
                        
                        if(draw_glsl_material(scene, ob, v3d, dt)) {
                                GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
@@ -3133,23 +3275,29 @@ static void draw_particle_arrays(int draw_as, int totpoint, int ob_dt, int selec
 static void draw_particle(ParticleKey *state, int draw_as, short draw, float pixsize, float imat[4][4], float *draw_line, ParticleBillboardData *bb, ParticleDrawData *pdd)
 {
        float vec[3], vec2[3];
-       float *vd = pdd->vd;
-       float *cd = pdd->cd;
+       float *vd = NULL;
+       float *cd = NULL;
        float ma_r=0.0f;
        float ma_g=0.0f;
        float ma_b=0.0f;
 
-       if(pdd->ma_r) {
-               ma_r = *pdd->ma_r;
-               ma_g = *pdd->ma_g;
-               ma_b = *pdd->ma_b;
+       /* 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;
+               }
        }
 
        switch(draw_as){
                case PART_DRAW_DOT:
                {
                        if(vd) {
-                               VECCOPY(vd,state->co) pdd->vd+=3;
+                               copy_v3_v3(vd,state->co); pdd->vd+=3;
                        }
                        if(cd) {
                                cd[0]=ma_r;
@@ -3174,7 +3322,7 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                                cd[14]=cd[17]=1.0;
                                pdd->cd+=18;
 
-                               VECCOPY(vec2,state->co);
+                               copy_v3_v3(vec2,state->co);
                        }
                        else {
                                if(cd) {
@@ -3183,47 +3331,47 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                                        cd[2]=cd[5]=cd[8]=cd[11]=cd[14]=cd[17]=ma_b;
                                        pdd->cd+=18;
                                }
-                               VECSUB(vec2,state->co,vec);
+                               sub_v3_v3v3(vec2, state->co, vec);
                        }
 
-                       VECADD(vec,state->co,vec);
-                       VECCOPY(pdd->vd,vec); pdd->vd+=3;
-                       VECCOPY(pdd->vd,vec2); pdd->vd+=3;
+                       add_v3_v3(vec, state->co);
+                       copy_v3_v3(pdd->vd,vec); pdd->vd+=3;
+                       copy_v3_v3(pdd->vd,vec2); pdd->vd+=3;
                                
                        vec[1]=2.0f*pixsize;
                        vec[0]=vec[2]=0.0;
                        mul_qt_v3(state->rot,vec);
                        if(draw_as==PART_DRAW_AXIS){
-                               VECCOPY(vec2,state->co);
+                               copy_v3_v3(vec2,state->co);
                        }               
-                       else VECSUB(vec2,state->co,vec);
+                       else sub_v3_v3v3(vec2, state->co, vec);
 
-                       VECADD(vec,state->co,vec);
-                       VECCOPY(pdd->vd,vec); pdd->vd+=3;
-                       VECCOPY(pdd->vd,vec2); pdd->vd+=3;
+                       add_v3_v3(vec, state->co);
+                       copy_v3_v3(pdd->vd,vec); pdd->vd+=3;
+                       copy_v3_v3(pdd->vd,vec2); pdd->vd+=3;
 
                        vec[2]=2.0f*pixsize;
                        vec[0]=vec[1]=0.0;
                        mul_qt_v3(state->rot,vec);
                        if(draw_as==PART_DRAW_AXIS){
-                               VECCOPY(vec2,state->co);
+                               copy_v3_v3(vec2,state->co);
                        }
-                       else VECSUB(vec2,state->co,vec);
+                       else sub_v3_v3v3(vec2, state->co, vec);
 
-                       VECADD(vec,state->co,vec);
+                       add_v3_v3(vec, state->co);
 
-                       VECCOPY(pdd->vd,vec); pdd->vd+=3;
-                       VECCOPY(pdd->vd,vec2); pdd->vd+=3;
+                       copy_v3_v3(pdd->vd,vec); pdd->vd+=3;
+                       copy_v3_v3(pdd->vd,vec2); pdd->vd+=3;
                        break;
                }
                case PART_DRAW_LINE:
                {
-                       VECCOPY(vec,state->vel);
+                       copy_v3_v3(vec,state->vel);
                        normalize_v3(vec);
                        if(draw & PART_DRAW_VEL_LENGTH)
                                mul_v3_fl(vec,len_v3(state->vel));
-                       VECADDFAC(pdd->vd,state->co,vec,-draw_line[0]); pdd->vd+=3;
-                       VECADDFAC(pdd->vd,state->co,vec,draw_line[1]); pdd->vd+=3;
+                       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;
@@ -3234,8 +3382,6 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                }
                case PART_DRAW_CIRC:
                {
-                       if(pdd->ma_r)
-                               glColor3f(ma_r,ma_g,ma_b);
                        drawcircball(GL_LINE_LOOP, state->co, pixsize, imat);
                        break;
                }
@@ -3250,27 +3396,27 @@ static void draw_particle(ParticleKey *state, int draw_as, short draw, float pix
                        }
 
 
-                       VECCOPY(bb->vec, state->co);
-                       VECCOPY(bb->vel, state->vel);
+                       copy_v3_v3(bb->vec, state->co);
+                       copy_v3_v3(bb->vel, state->vel);
 
                        psys_make_billboard(bb, xvec, yvec, zvec, bb_center);
                        
-                       VECADD(pdd->vd,bb_center,xvec);
-                       VECADD(pdd->vd,pdd->vd,yvec); pdd->vd+=3;
+                       add_v3_v3v3(pdd->vd, bb_center, xvec);
+                       add_v3_v3(pdd->vd, yvec); pdd->vd+=3;
 
-                       VECSUB(pdd->vd,bb_center,xvec);
-                       VECADD(pdd->vd,pdd->vd,yvec); pdd->vd+=3;
+                       sub_v3_v3v3(pdd->vd, bb_center, xvec);
+                       add_v3_v3(pdd->vd, yvec); pdd->vd+=3;
 
-                       VECSUB(pdd->vd,bb_center,xvec);
-                       VECSUB(pdd->vd,pdd->vd,yvec); pdd->vd+=3;
+                       sub_v3_v3v3(pdd->vd, bb_center, xvec);
+                       sub_v3_v3v3(pdd->vd, pdd->vd,yvec); pdd->vd+=3;
 
-                       VECADD(pdd->vd,bb_center,xvec);
-                       VECSUB(pdd->vd,pdd->vd,yvec); pdd->vd+=3;
+                       add_v3_v3v3(pdd->vd, bb_center, xvec);
+                       sub_v3_v3v3(pdd->vd, pdd->vd, yvec); pdd->vd+=3;
 
-                       VECCOPY(pdd->nd, zvec); pdd->nd+=3;
-                       VECCOPY(pdd->nd, zvec); pdd->nd+=3;
-                       VECCOPY(pdd->nd, zvec); pdd->nd+=3;
-                       VECCOPY(pdd->nd, zvec); pdd->nd+=3;
+                       copy_v3_v3(pdd->nd, zvec); pdd->nd+=3;
+                       copy_v3_v3(pdd->nd, zvec); pdd->nd+=3;
+                       copy_v3_v3(pdd->nd, zvec); pdd->nd+=3;
+                       copy_v3_v3(pdd->nd, zvec); pdd->nd+=3;
                        break;
                }
        }
@@ -3294,7 +3440,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
        ParticleData *pars, *pa;
        ParticleKey state, *states=0;
        ParticleBillboardData bb;
-       ParticleSimulationData sim = {scene, ob, psys, NULL};
+       ParticleSimulationData sim= {0};
        ParticleDrawData *pdd = psys->pdd;
        Material *ma;
        float vel[3], imat[4][4];
@@ -3332,6 +3478,9 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                return;
 
 /* 2. */
+       sim.scene= scene;
+       sim.ob= ob;
+       sim.psys= psys;
        sim.psmd = psmd = psys_get_modifier(ob,psys);
 
        if(part->phystype==PART_PHYS_KEYED){
@@ -3369,12 +3518,6 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
        else
                cpack(0);
 
-       if(pdd) {
-               pdd->ma_r = &ma_r;
-               pdd->ma_g = &ma_g;
-               pdd->ma_b = &ma_b;
-       }
-
        timestep= psys_get_timestep(&sim);
 
        if( (base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP) ) {
@@ -3383,9 +3526,11 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                glMultMatrixf(mat);
        }
 
+       /* needed for text display */
+       invert_m4_m4(ob->imat, ob->obmat);
+
        totpart=psys->totpart;
 
-       //if(part->flag&PART_GLOB_TIME)
        cfra=bsystem_time(scene, 0, (float)CFRA, 0.0f);
 
        if(draw_as==PART_DRAW_PATH && psys->pathcache==NULL && psys->childcache==NULL)
@@ -3408,8 +3553,8 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                case PART_DRAW_CROSS:
                case PART_DRAW_AXIS:
                        /* lets calculate the scale: */
-                       pixsize= rv3d->persmat[0][3]*ob->obmat[3][0]+ rv3d->persmat[1][3]*ob->obmat[3][1]+ rv3d->persmat[2][3]*ob->obmat[3][2]+ rv3d->persmat[3][3];
-                       pixsize*= rv3d->pixsize;
+                       pixsize= view3d_pixel_size(rv3d, ob->obmat[3]);
+                       
                        if(part->draw_size==0.0)
                                pixsize*=2.0;
                        else
@@ -3526,11 +3671,18 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                pdd->tot_vec_size= tot_vec_size;
        }
 
+       if(pdd) {
+               pdd->ma_r = &ma_r;
+               pdd->ma_g = &ma_g;
+               pdd->ma_b = &ma_b;
+       }
+
        psys->lattice= psys_get_lattice(&sim);
 
-       if(pdd && draw_as!=PART_DRAW_PATH){
+       /* circles don't use drawdata, so have to add a special case here */
+       if((pdd || draw_as==PART_DRAW_CIRC) && draw_as!=PART_DRAW_PATH){
 /* 5. */
-               if((pdd->flag & PARTICLE_DRAW_DATA_UPDATED)
+               if(pdd && (pdd->flag & PARTICLE_DRAW_DATA_UPDATED)
                        && (pdd->vedata || part->draw & (PART_DRAW_SIZE|PART_DRAW_NUM|PART_DRAW_HEALTH))==0) {
                        totpoint = pdd->totpoint; /* draw data is up to date */
                }
@@ -3677,11 +3829,10 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                                /* additional things to draw for each particle  */
                                /* (velocity, size and number)                                  */
                                if((part->draw & PART_DRAW_VEL) && pdd->vedata){
-                                       VECCOPY(pdd->ved,state.co);
-                                       pdd->ved+=3;
-                                       VECCOPY(vel,state.vel);
-                                       mul_v3_fl(vel,timestep);
-                                       VECADD(pdd->ved,state.co,vel);
+                                       copy_v3_v3(pdd->ved,state.co);
+                                       pdd->ved += 3;
+                                       mul_v3_v3fl(vel, state.vel, timestep);
+                                       add_v3_v3v3(pdd->ved, state.co, vel);
                                        pdd->ved+=3;
 
                                        totve++;
@@ -3693,22 +3844,30 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                                        setlinestyle(0);
                                }
 
-                               if((part->draw&PART_DRAW_NUM || part->draw&PART_DRAW_HEALTH) && !(G.f & G_RENDER_SHADOW)){
-                                       val[0]= '\0';
-                                       
-                                       if(part->draw&PART_DRAW_NUM)
-                                               sprintf(val, " %i", a);
 
-                                       if(part->draw&PART_DRAW_NUM && part->draw&PART_DRAW_HEALTH)
-                                               strcat(val, ":");
+                               if((part->draw & PART_DRAW_NUM || part->draw & PART_DRAW_HEALTH) && (v3d->flag2 & V3D_RENDER_OVERRIDE)==0){
+                                       float vec_txt[3];
+                                       char *val_pos= val;
+                                       val[0]= '\0';
 
-                                       if(part->draw&PART_DRAW_HEALTH && a < totpart && part->phystype==PART_PHYS_BOIDS) {
-                                               char tval[8];
-                                               sprintf(tval, " %.2f", pa_health);
-                                               strcat(val, tval);
+                                       if(part->draw&PART_DRAW_NUM) {
+                                               if(a < totpart && (part->draw & PART_DRAW_HEALTH) && (part->phystype==PART_PHYS_BOIDS)) {
+                                                       sprintf(val_pos, "%d:%.2f", a, pa_health);
+                                               }
+                                               else {
+                                                       sprintf(val_pos, "%d", a);
+                                               }
+                                       }
+                                       else {
+                                               if(a < totpart && (part->draw & PART_DRAW_HEALTH) && (part->phystype==PART_PHYS_BOIDS)) {
+                                                       sprintf(val_pos, "%.2f", pa_health);
+                                               }
                                        }
+
                                        /* in path drawing state.co is the end point */
-                                       view3d_cached_text_draw_add(state.co[0],  state.co[1],  state.co[2], val, 0, 0);
+                                       /* use worldspace beause object matrix is already applied */
+                                       mul_v3_m4v3(vec_txt, ob->imat, state.co);
+                                       view3d_cached_text_draw_add(vec_txt, val, 10, V3D_CACHE_TEXT_WORLDSPACE|V3D_CACHE_TEXT_ASCII);
                                }
                        }
                }
@@ -3723,7 +3882,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                float *cd2=0,*cdata2=0;
 
                /* setup gl flags */
-               if(ob_dt > OB_WIRE) {
+               if (1) { //ob_dt > OB_WIRE) {
                        glEnableClientState(GL_NORMAL_ARRAY);
 
                        if(part->draw&PART_DRAW_MAT_COL)
@@ -3733,13 +3892,13 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                        glEnable(GL_COLOR_MATERIAL);
                }
-               else {
+               /*else {
                        glDisableClientState(GL_NORMAL_ARRAY);
 
                        glDisable(GL_COLOR_MATERIAL);
                        glDisable(GL_LIGHTING);
                        UI_ThemeColor(TH_WIRE);
-               }
+               }*/
 
                if(totchild && (part->draw&PART_DRAW_PARENT)==0)
                        totpart=0;
@@ -3753,7 +3912,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                        if(path->steps > 0) {
                                glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
 
-                               if(ob_dt > OB_WIRE) {
+                               if(1) { //ob_dt > OB_WIRE) {
                                        glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
                                        if(part->draw&PART_DRAW_MAT_COL)
                                                glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
@@ -3769,7 +3928,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                        path=cache[a];
                        glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
 
-                       if(ob_dt > OB_WIRE) {
+                       if(1) { //ob_dt > OB_WIRE) {
                                glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
                                if(part->draw&PART_DRAW_MAT_COL)
                                        glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
@@ -3780,7 +3939,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 
 
                /* restore & clean up */
-               if(ob_dt > OB_WIRE) {
+               if(1) { //ob_dt > OB_WIRE) {
                        if(part->draw&PART_DRAW_MAT_COL)
                                glDisable(GL_COLOR_ARRAY);
                        glDisable(GL_COLOR_MATERIAL);
@@ -3791,6 +3950,18 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                cd2=cdata2=0;
 
                glLineWidth(1.0f);
+
+               if((part->draw & PART_DRAW_NUM) && (v3d->flag2 & V3D_RENDER_OVERRIDE)==0){
+                       cache=psys->pathcache;
+
+                       for(a=0, pa=psys->particles; a<totpart; a++, pa++){
+                               float vec_txt[3];
+                               sprintf(val, "%i", a);
+                               /* use worldspace beause object matrix is already applied */
+                               mul_v3_m4v3(vec_txt, ob->imat, cache[a]->co);
+                               view3d_cached_text_draw_add(vec_txt, val, 10, V3D_CACHE_TEXT_WORLDSPACE|V3D_CACHE_TEXT_ASCII);
+                       }
+               }
        }
        else if(pdd && ELEM(draw_as, 0, PART_DRAW_CIRC)==0){
                glDisableClientState(GL_COLOR_ARRAY);
@@ -3894,7 +4065,7 @@ static void draw_update_ptcache_edit(Scene *scene, Object *ob, PTCacheEdit *edit
                psys_cache_edit_paths(scene, ob, edit, CFRA);
 }
 
-static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, PTCacheEdit *edit, int dt)
+static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit)
 {
        ParticleCacheKey **cache, *path, *pkey;
        PTCacheEditPoint *point;
@@ -3929,8 +4100,8 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
 
-       glEnable(GL_COLOR_MATERIAL);
        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+       glEnable(GL_COLOR_MATERIAL);
        glShadeModel(GL_SMOOTH);
 
        if(pset->brushtype == PE_BRUSH_WEIGHT) {
@@ -3945,7 +4116,7 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
 
                if(timed) {
                        for(k=0, pcol=pathcol, pkey=path; k<steps; k++, pkey++, pcol+=4){
-                               VECCOPY(pcol, pkey->col);
+                               copy_v3_v3(pcol, pkey->col);
                                pcol[3] = 1.0f - fabs((float)CFRA - pkey->time)/(float)pset->fade_frames;
                        }
 
@@ -3983,15 +4154,15 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
 
                                for(k=0, key=point->keys; k<point->totkey; k++, key++){
                                        if(pd) {
-                                               VECCOPY(pd, key->co);
+                                               copy_v3_v3(pd, key->co);
                                                pd += 3;
                                        }
 
                                        if(key->flag&PEK_SELECT){
-                                               VECCOPY(cd,sel_col);
+                                               copy_v3_v3(cd,sel_col);
                                        }
                                        else{
-                                               VECCOPY(cd,nosel_col);
+                                               copy_v3_v3(cd,nosel_col);
                                        }
 
                                        if(timed)
@@ -4065,12 +4236,12 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[1] = root[2] = 0.0f;
        root[0] = -drw_size;
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        tip[1] = tip[2] = 0.0f;
        tip[0] = drw_size;
        mul_m3_v3(tr,tip);
-       VECADD(tip,tip,com);
+       add_v3_v3(tip, com);
        glVertex3fv(tip); 
        glEnd();
 
@@ -4078,7 +4249,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4087,7 +4258,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4096,7 +4267,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] =th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4105,7 +4276,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4116,12 +4287,12 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] = root[2] = 0.0f;
        root[1] = -drw_size;
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        tip[0] = tip[2] = 0.0f;
        tip[1] = drw_size;
        mul_m3_v3(tr,tip);
-       VECADD(tip,tip,com);
+       add_v3_v3(tip, com);
        glVertex3fv(tip); 
        glEnd();
 
@@ -4129,7 +4300,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[1] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4138,7 +4309,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[1] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4147,7 +4318,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[1] =th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4156,7 +4327,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[1] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4166,12 +4337,12 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[0] = root[1] = 0.0f;
        root[2] = -drw_size;
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        tip[0] = tip[1] = 0.0f;
        tip[2] = drw_size;
        mul_m3_v3(tr,tip);
-       VECADD(tip,tip,com);
+       add_v3_v3(tip, com);
        glVertex3fv(tip); 
        glEnd();
 
@@ -4179,7 +4350,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[2] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4188,7 +4359,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[2] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4197,7 +4368,7 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[2] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
@@ -4206,30 +4377,28 @@ static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float
        root[2] = th;
        glBegin(GL_LINES);
        mul_m3_v3(tr,root);
-       VECADD(root,root,com);
+       add_v3_v3(root, com);
        glVertex3fv(root); 
        glVertex3fv(tip); 
        glEnd();
 }
 
 /*place to add drawers */
-unsigned int nurbcol[8]= {
-       0, 0x9090, 0x409030, 0x603080, 0, 0x40fff0, 0x40c033, 0xA090F0 };
 
 static void tekenhandlesN(Nurb *nu, short sel, short hide_handles)
 {
        BezTriple *bezt;
        float *fp;
-       unsigned int *col;
+       int basecol;
        int a;
        
        if(nu->hide || hide_handles) return;
-       
+
        glBegin(GL_LINES); 
        
        if(nu->type == CU_BEZIER) {
-               if(sel) col= nurbcol+4;
-               else col= nurbcol;
+               if(sel) basecol= TH_HANDLE_SEL_FREE;
+               else basecol= TH_HANDLE_FREE;
 
                bezt= nu->bezt;
                a= nu->pntsu;
@@ -4237,26 +4406,26 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles)
                        if(bezt->hide==0) {
                                if( (bezt->f2 & SELECT)==sel) {
                                        fp= bezt->vec[0];
-                                       
-                                       cpack(col[(int)bezt->h1]);
+
+                                       UI_ThemeColor(basecol + bezt->h1);
                                        glVertex3fv(fp);
                                        glVertex3fv(fp+3); 
 
-                                       cpack(col[(int)bezt->h2]);
+                                       UI_ThemeColor(basecol + bezt->h2);
                                        glVertex3fv(fp+3); 
                                        glVertex3fv(fp+6); 
                                }
                                else if( (bezt->f1 & SELECT)==sel) {
                                        fp= bezt->vec[0];
-                                       
-                                       cpack(col[(int)bezt->h1]);
+
+                                       UI_ThemeColor(basecol + bezt->h1);
                                        glVertex3fv(fp); 
                                        glVertex3fv(fp+3); 
                                }
                                else if( (bezt->f3 & SELECT)==sel) {
                                        fp= bezt->vec[1];
-                                       
-                                       cpack(col[(int)bezt->h2]);
+
+                                       UI_ThemeColor(basecol + bezt->h2);
                                        glVertex3fv(fp); 
                                        glVertex3fv(fp+3); 
                                }
@@ -4267,17 +4436,54 @@ static void tekenhandlesN(Nurb *nu, short sel, short hide_handles)
        glEnd();
 }
 
-static void tekenvertsN(Nurb *nu, short sel, short hide_handles)
+static void tekenhandlesN_active(Nurb *nu)
+{
+       BezTriple *bezt;
+       float *fp;
+       int a;
+
+       if(nu->hide) return;
+
+       UI_ThemeColor(TH_ACTIVE_SPLINE);
+       glLineWidth(2);
+
+       glBegin(GL_LINES);
+
+       if(nu->type == CU_BEZIER) {
+               bezt= nu->bezt;
+               a= nu->pntsu;
+               while(a--) {
+                       if(bezt->hide==0) {
+                               fp= bezt->vec[0];
+
+                               glVertex3fv(fp);
+                               glVertex3fv(fp+3);
+
+                               glVertex3fv(fp+3);
+                               glVertex3fv(fp+6);
+                       }
+                       bezt++;
+               }
+       }
+       glEnd();
+
+       glColor3ub(0,0,0);
+       glLineWidth(1);
+}
+
+static void tekenvertsN(Nurb *nu, short sel, short hide_handles, void *lastsel)
 {
        BezTriple *bezt;
        BPoint *bp;
        float size;
-       int a;
+       int a, color;
 
        if(nu->hide) return;
 
-       if(sel) UI_ThemeColor(TH_VERTEX_SELECT);
-       else UI_ThemeColor(TH_VERTEX);
+       if(sel) color= TH_VERTEX_SELECT;
+       else color= TH_VERTEX;
+
+       UI_ThemeColor(color);
 
        size= UI_GetThemeValuef(TH_VERTEX_SIZE);
        glPointSize(size);
@@ -4290,7 +4496,17 @@ static void tekenvertsN(Nurb *nu, short sel, short hide_handles)
                a= nu->pntsu;
                while(a--) {
                        if(bezt->hide==0) {
-                               if (hide_handles) {
+                               if (sel == 1 && bezt == lastsel) {
+                                       UI_ThemeColor(TH_LASTSEL_POINT);
+                                       bglVertex3fv(bezt->vec[1]);
+
+                                       if (!hide_handles) {
+                                               if(bezt->f1 & SELECT) bglVertex3fv(bezt->vec[0]);
+                                               if(bezt->f3 & SELECT) bglVertex3fv(bezt->vec[2]);
+                                       }
+
+                                       UI_ThemeColor(color);
+                               } else if (hide_handles) {
                                        if((bezt->f2 & SELECT)==sel) bglVertex3fv(bezt->vec[1]);
                                } else {
                                        if((bezt->f1 & SELECT)==sel) bglVertex3fv(bezt->vec[0]);
@@ -4306,7 +4522,13 @@ static void tekenvertsN(Nurb *nu, short sel, short hide_handles)
                a= nu->pntsu*nu->pntsv;
                while(a--) {
                        if(bp->hide==0) {
-                               if((bp->f1 & SELECT)==sel) bglVertex3fv(bp->vec);
+                               if (bp == lastsel) {
+                                       UI_ThemeColor(TH_LASTSEL_POINT);
+                                       bglVertex3fv(bp->vec);
+                                       UI_ThemeColor(color);
+                               } else {
+                                       if((bp->f1 & SELECT)==sel) bglVertex3fv(bp->vec);
+                               }
                        }
                        bp++;
                }
@@ -4316,18 +4538,94 @@ static void tekenvertsN(Nurb *nu, short sel, short hide_handles)
        glPointSize(1.0);
 }
 
+static void editnurb_draw_active_poly(Nurb *nu)
+{
+       BPoint *bp;
+       int a, b;
+
+       UI_ThemeColor(TH_ACTIVE_SPLINE);
+       glLineWidth(2);
+
+       bp= nu->bp;
+       for(b=0; b<nu->pntsv; b++) {
+               if(nu->flagu & 1) glBegin(GL_LINE_LOOP);
+               else glBegin(GL_LINE_STRIP);
+
+               for(a=0; a<nu->pntsu; a++, bp++) {
+                       glVertex3fv(bp->vec);
+               }
+
+               glEnd();
+       }
+
+       glColor3ub(0,0,0);
+       glLineWidth(1);
+}
+
+static void editnurb_draw_active_nurbs(Nurb *nu)
+{
+       BPoint *bp, *bp1;
+       int a, b, ofs;
+
+       UI_ThemeColor(TH_ACTIVE_SPLINE);
+       glLineWidth(2);
+
+       glBegin(GL_LINES);
+       bp= nu->bp;
+       for(b=0; b<nu->pntsv; b++) {
+               bp1= bp;
+               bp++;
+
+               for(a=nu->pntsu-1; a>0; a--, bp++) {
+                       if(bp->hide==0 && bp1->hide==0) {
+                               glVertex3fv(bp->vec);
+                               glVertex3fv(bp1->vec);
+                       }
+                       bp1= bp;
+               }
+       }
+
+       if(nu->pntsv > 1) {     /* surface */
+
+               ofs= nu->pntsu;
+               for(b=0; b<nu->pntsu; b++) {
+                       bp1= nu->bp+b;
+                       bp= bp1+ofs;
+                       for(a=nu->pntsv-1; a>0; a--, bp+=ofs) {
+                               if(bp->hide==0 && bp1->hide==0) {
+                                       glVertex3fv(bp->vec);
+                                       glVertex3fv(bp1->vec);
+                               }
+                               bp1= bp;
+                       }
+               }
+       }
+
+       glEnd();
+
+       glColor3ub(0,0,0);
+       glLineWidth(1);
+}
+
 static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
 {
        Nurb *nu;
        BPoint *bp, *bp1;
-       int a, b, ofs;
-       
+       int a, b, ofs, index;
+       Curve *cu= (Curve*)ob->data;
+
+       index= 0;
        nu= nurb;
        while(nu) {
                if(nu->hide==0) {
                        switch(nu->type) {
                        case CU_POLY:
-                               cpack(nurbcol[3]);
+                               if (!sel && index== cu->actnu) {
+                                       /* we should draw active spline highlight below everything */
+                                       editnurb_draw_active_poly(nu);
+                               }
+
+                               UI_ThemeColor(TH_NURB_ULINE);
                                bp= nu->bp;
                                for(b=0; b<nu->pntsv; b++) {
                                        if(nu->flagu & 1) glBegin(GL_LINE_LOOP);
@@ -4341,6 +4639,10 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                }
                                break;
                        case CU_NURBS:
+                               if (!sel && index== cu->actnu) {
+                                       /* we should draw active spline highlight below everything */
+                                       editnurb_draw_active_nurbs(nu);
+                               }
 
                                bp= nu->bp;
                                for(b=0; b<nu->pntsv; b++) {
@@ -4350,7 +4652,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                                if(bp->hide==0 && bp1->hide==0) {
                                                        if(sel) {
                                                                if( (bp->f1 & SELECT) && ( bp1->f1 & SELECT ) ) {
-                                                                       cpack(nurbcol[5]);
+                                                                       UI_ThemeColor(TH_NURB_SEL_ULINE);
                
                                                                        glBegin(GL_LINE_STRIP);
                                                                        glVertex3fv(bp->vec); 
@@ -4361,7 +4663,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                                        else {
                                                                if( (bp->f1 & SELECT) && ( bp1->f1 & SELECT) );
                                                                else {
-                                                                       cpack(nurbcol[1]);
+                                                                       UI_ThemeColor(TH_NURB_ULINE);
                
                                                                        glBegin(GL_LINE_STRIP);
                                                                        glVertex3fv(bp->vec); 
@@ -4383,7 +4685,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                                        if(bp->hide==0 && bp1->hide==0) {
                                                                if(sel) {
                                                                        if( (bp->f1 & SELECT) && ( bp1->f1 & SELECT) ) {
-                                                                               cpack(nurbcol[7]);
+                                                                               UI_ThemeColor(TH_NURB_SEL_VLINE);
                        
                                                                                glBegin(GL_LINE_STRIP);
                                                                                glVertex3fv(bp->vec); 
@@ -4394,7 +4696,7 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                                                else {
                                                                        if( (bp->f1 & SELECT) && ( bp1->f1 & SELECT) );
                                                                        else {
-                                                                               cpack(nurbcol[3]);
+                                                                               UI_ThemeColor(TH_NURB_VLINE);
                        
                                                                                glBegin(GL_LINE_STRIP);
                                                                                glVertex3fv(bp->vec); 
@@ -4411,6 +4713,8 @@ static void draw_editnurb(Object *ob, Nurb *nurb, int sel)
                                break;
                        }
                }
+
+               ++index;
                nu= nu->next;
        }
 }
@@ -4423,6 +4727,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        Nurb *nu;
        BevList *bl;
        short hide_handles = (cu->drawflag & CU_HIDE_HANDLES);
+       int index;
 
 // XXX retopo_matrix_update(v3d);
 
@@ -4432,11 +4737,15 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
        if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
-       /* first non-selected handles */
+       /* first non-selected and active handles */
+       index= 0;
        for(nu=nurb; nu; nu=nu->next) {
                if(nu->type == CU_BEZIER) {
+                       if (index == cu->actnu && !hide_handles)
+                               tekenhandlesN_active(nu);
                        tekenhandlesN(nu, 0, hide_handles);
                }
+               ++index;
        }
        draw_editnurb(ob, nurb, 0);
        draw_editnurb(ob, nurb, 1);
@@ -4444,7 +4753,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        for(nu=nurb; nu; nu=nu->next) {
                if(nu->type == CU_BEZIER && (cu->drawflag & CU_HIDE_HANDLES)==0)
                        tekenhandlesN(nu, 1, hide_handles);
-               tekenvertsN(nu, 0, hide_handles);
+               tekenvertsN(nu, 0, hide_handles, NULL);
        }
        
        if(v3d->zbuf) glEnable(GL_DEPTH_TEST);
@@ -4461,13 +4770,21 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        
                        while (nr-->0) { /* accounts for empty bevel lists */
                                float fac= bevp->radius * ts->normalsize;
-                               float vec_a[3] = { fac,0, 0}; // Offset perpendicular to the curve
-                               float vec_b[3] = {-fac,0, 0}; // Delta along the curve
+                               float vec_a[3]; // Offset perpendicular to the curve
+                               float vec_b[3]; // Delta along the curve
+
+                               vec_a[0]= fac;
+                               vec_a[1]= 0.0f;
+                               vec_a[2]= 0.0f;
 
+                               vec_b[0]= -fac;
+                               vec_b[1]= 0.0f;
+                               vec_b[2]= 0.0f;
+                               
                                mul_qt_v3(bevp->quat, vec_a);
                                mul_qt_v3(bevp->quat, vec_b);
-                               add_v3_v3v3(vec_a, vec_a, bevp->vec);
-                               add_v3_v3v3(vec_b, vec_b, bevp->vec);
+                               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);
@@ -4487,7 +4804,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        if(v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        for(nu=nurb; nu; nu=nu->next) {
-               tekenvertsN(nu, 1, hide_handles);
+               tekenvertsN(nu, 1, hide_handles, cu->lastsel);
        }
        
        if(v3d->zbuf) glEnable(GL_DEPTH_TEST); 
@@ -4502,7 +4819,7 @@ static void draw_empty_sphere (float size)
                GLUquadricObj   *qobj;
                
                displist= glGenLists(1);
-               glNewList(displist, GL_COMPILE_AND_EXECUTE);
+               glNewList(displist, GL_COMPILE);
                
                glPushMatrix();
                
@@ -4523,8 +4840,8 @@ static void draw_empty_sphere (float size)
        }
        
        glScalef(size, size, size);
-               glCallList(displist);
-       glScalef(1/size, 1/size, 1/size);
+       glCallList(displist);
+       glScalef(1.0f/size, 1.0f/size, 1.0f/size);
 }
 
 /* draw a cone for use as an empty drawtype */
@@ -4550,9 +4867,9 @@ static void draw_empty_cone (float size)
 }
 
 /* draw points on curve speed handles */
+#if 0 // XXX old animation system stuff
 static void curve_draw_speed(Scene *scene, Object *ob)
 {
-#if 0 // XXX old animation system stuff
        Curve *cu= ob->data;
        IpoCurve *icu;
        BezTriple *bezt;
@@ -4578,8 +4895,8 @@ static void curve_draw_speed(Scene *scene, Object *ob)
 
        glPointSize(1.0);
        bglEnd();
-#endif // XXX old animation system stuff
 }
+#endif // XXX old animation system stuff
 
 
 static void draw_textcurs(float textcurs[][2])
@@ -4607,12 +4924,10 @@ static void drawspiral(float *cent, float rad, float tmat[][4], int start)
                start *= -1;
        }
 
-       VECCOPY(vx, tmat[0]);
-       VECCOPY(vy, tmat[1]);
-       mul_v3_fl(vx, rad);
-       mul_v3_fl(vy, rad);
+       mul_v3_v3fl(vx, tmat[0], rad);
+       mul_v3_v3fl(vy, tmat[1], rad);
 
-       VECCOPY(vec, cent);
+       copy_v3_v3(vec, cent);
 
        if (inverse==0) {
                for(a=0; a<tot; a++) {
@@ -4734,6 +5049,8 @@ static int drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        }
 
        if(ml==NULL) return 1;
+
+       if(v3d->flag2 & V3D_RENDER_OVERRIDE) return 0;
        
        /* in case solid draw, reset wire colors */
        if(ob->flag & SELECT) {
@@ -4785,9 +5102,6 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
        int curcol;
        float size;
 
-       if(G.f & G_RENDER_SHADOW)
-               return;
-       
        /* XXX why? */
        if(ob!=scene->obedit && (ob->flag & SELECT)) {
                if(ob==OBACT) curcol= TH_ACTIVE;
@@ -4876,17 +5190,17 @@ static void draw_forcefield(Scene *scene, Object *ob, RegionView3D *rv3d)
 
                        /*path end*/
                        setlinestyle(3);
-                       where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL);
+                       where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL, NULL);
                        UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
 
                        /*path beginning*/
                        setlinestyle(0);
-                       where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL);
+                       where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL, NULL);
                        UI_ThemeColorBlend(curcol, TH_BACK, 0.5);
                        drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
                        
-                       VECCOPY(vec, guidevec1);        /* max center */
+                       copy_v3_v3(vec, guidevec1);     /* max center */
                }
        }
 
@@ -4972,8 +5286,8 @@ void get_local_bounds(Object *ob, float *center, float *size)
        BoundBox *bb= object_get_boundbox(ob);
        
        if(bb==NULL) {
-               center[0]= center[1]= center[2]= 0.0;
-               VECCOPY(size, ob->size);
+               zero_v3(center);
+               copy_v3_v3(size, ob->size);
        }
        else {
                size[0]= 0.5*fabs(bb->vec[0][0] - bb->vec[4][0]);
@@ -5035,13 +5349,15 @@ static void draw_bounding_volume(Scene *scene, Object *ob)
                bb= mesh_get_bb(ob);
        }
        else if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) {
-               bb= ( (Curve *)ob->data )->bb;
+               bb= ob->bb ? ob->bb : ( (Curve *)ob->data )->bb;
        }
        else if(ob->type==OB_MBALL) {
-               bb= ob->bb;
-               if(bb==0) {
-                       makeDispListMBall(scene, ob);
+               if(is_basis_mball(ob)) {
                        bb= ob->bb;
+                       if(bb==0) {
+                               makeDispListMBall(scene, ob);
+                               bb= ob->bb;
+                       }
                }
        }
        else {
@@ -5065,13 +5381,13 @@ static void drawtexspace(Object *ob)
        }
        else if ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT) {
                Curve *cu= ob->data;
-               VECCOPY(size, cu->size);
-               VECCOPY(loc, cu->loc);
+               copy_v3_v3(size, cu->size);
+               copy_v3_v3(loc, cu->loc);
        }
        else if(ob->type==OB_MBALL) {
                MetaBall *mb= ob->data;
-               VECCOPY(size, mb->size);
-               VECCOPY(loc, mb->loc);
+               copy_v3_v3(size, mb->size);
+               copy_v3_v3(loc, mb->loc);
        }
        else return;
        
@@ -5092,7 +5408,7 @@ static void drawtexspace(Object *ob)
 }
 
 /* draws wire outline */
-static void drawSolidSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base) 
+static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 {
        RegionView3D *rv3d= ar->regiondata;
        Object *ob= base->object;
@@ -5102,14 +5418,29 @@ static void drawSolidSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
        
        if(ELEM3(ob->type, OB_FONT,OB_CURVE, OB_SURF)) {
                Curve *cu = ob->data;
-               if (displist_has_faces(&cu->disp) && boundbox_clip(rv3d, ob->obmat, cu->bb)) {
+               DerivedMesh *dm = ob->derivedFinal;
+               int hasfaces= 0;
+
+               if (dm) {
+                       hasfaces= dm->getNumFaces(dm);
+               } else {
+                       hasfaces= displist_has_faces(&cu->disp);
+               }
+
+               if (hasfaces && boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
                        draw_index_wire= 0;
-                       drawDispListwire(&cu->disp);
+                       if (dm) {
+                               draw_mesh_object_outline(v3d, ob, dm);
+                       } else {
+                               drawDispListwire(&cu->disp);
+                       }
                        draw_index_wire= 1;
                }
        } else if (ob->type==OB_MBALL) {
-               if((base->flag & OB_FROMDUPLI)==0) 
-                       drawDispListwire(&ob->disp);
+               if(is_basis_mball(ob)) {
+                       if((base->flag & OB_FROMDUPLI)==0)
+                               drawDispListwire(&ob->disp);
+               }
        }
        else if(ob->type==OB_ARMATURE) {
                if(!(ob->mode & OB_MODE_POSE))
@@ -5149,15 +5480,23 @@ static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob)
        
        if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
                Curve *cu = ob->data;
-               if (boundbox_clip(rv3d, ob->obmat, cu->bb)) {
+               if (boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
                        if (ob->type==OB_CURVE)
                                draw_index_wire= 0;
-                       drawDispListwire(&cu->disp);
+
+                       if (ob->derivedFinal) {
+                               drawCurveDMWired(ob);
+                       } else {
+                               drawDispListwire(&cu->disp);
+                       }
+
                        if (ob->type==OB_CURVE)
                                draw_index_wire= 1;
                }
        } else if (ob->type==OB_MBALL) {
-               drawDispListwire(&ob->disp);
+               if(is_basis_mball(ob)) {
+                       drawDispListwire(&ob->disp);
+               }
        }
 
        glDepthMask(1);
@@ -5197,37 +5536,31 @@ static void draw_hooks(Object *ob)
 //<rcruiz>
 void drawRBpivot(bRigidBodyJointConstraint *data)
 {
-       float radsPerDeg = 6.283185307179586232f / 360.f;
        int axis;
-       float v1[3]= {data->pivX, data->pivY, data->pivZ};
-       float eu[3]= {radsPerDeg*data->axX, radsPerDeg*data->axY, radsPerDeg*data->axZ};
        float mat[4][4];
 
-       if(G.f & G_RENDER_SHADOW)
-               return;
-
-       eul_to_mat4(mat,eu);
+       eul_to_mat4(mat,&data->axX);
        glLineWidth (4.0f);
        setlinestyle(2);
        for (axis=0; axis<3; axis++) {
                float dir[3] = {0,0,0};
-               float v[3]= {data->pivX, data->pivY, data->pivZ};
+               float v[3];
+
+               copy_v3_v3(v, &data->pivX);
 
                dir[axis] = 1.f;
                glBegin(GL_LINES);
                mul_m4_v3(mat,dir);
-               v[0] += dir[0];
-               v[1] += dir[1];
-               v[2] += dir[2];
-               glVertex3fv(v1);
+               add_v3_v3(v, dir);
+               glVertex3fv(&data->pivX);
                glVertex3fv(v);                 
                glEnd();
                if (axis==0)
-                       view3d_cached_text_draw_add(v[0], v[1], v[2], "px", 0, 0);
+                       view3d_cached_text_draw_add(v, "px", 0, V3D_CACHE_TEXT_ASCII);
                else if (axis==1)
-                       view3d_cached_text_draw_add(v[0], v[1], v[2], "py", 0, 0);
+                       view3d_cached_text_draw_add(v, "py", 0, V3D_CACHE_TEXT_ASCII);
                else
-                       view3d_cached_text_draw_add(v[0], v[1], v[2], "pz", 0, 0);
+                       view3d_cached_text_draw_add(v, "pz", 0, V3D_CACHE_TEXT_ASCII);
        }
        glLineWidth (1.0f);
        setlinestyle(0);
@@ -5256,6 +5589,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        if (ob!=scene->obedit) {
                if (ob->restrictflag & OB_RESTRICT_VIEW) 
                        return;
+               if ((ob->restrictflag & OB_RESTRICT_RENDER) && 
+                       (v3d->flag2 & V3D_RENDER_OVERRIDE))
+                       return;
        }
 
        /* XXX particles are not safe for simultaneous threaded render */
@@ -5268,7 +5604,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                if(!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
                        /* xray and transp are set when it is drawing the 2nd/3rd pass */
                        if(!v3d->xray && !v3d->transp && (ob->dtx & OB_DRAWXRAY) && !(ob->dtx & OB_DRAWTRANSP)) {
-                               add_view3d_after(v3d, base, V3D_XRAY, flag);
+                               add_view3d_after(&v3d->afterdraw_xray, base, flag);
                                return;
                        }
                }
@@ -5362,13 +5698,13 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                bAnimVizSettings *avs= &ob->avs;
                
                /* setup drawing environment for paths */
-               draw_motion_paths_init(scene, v3d, ar);
+               draw_motion_paths_init(v3d, ar);
                
                /* draw motion path for object */
-               draw_motion_path_instance(scene, v3d, ar, ob, NULL, avs, ob->mpath);
+               draw_motion_path_instance(scene, ob, NULL, avs, ob->mpath);
                
                /* cleanup after drawing */
-               draw_motion_paths_cleanup(scene, v3d, ar);
+               draw_motion_paths_cleanup(v3d);
        }
 
        /* multiply view with object matrix.
@@ -5470,12 +5806,12 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                if (cu->disp.first==NULL) makeDispListCurveTypes(scene, ob, 0);
        }
        
-       /* draw outline for selected solid objects, mesh does itself */
-       if((v3d->flag & V3D_SELECT_OUTLINE) && ob->type!=OB_MESH) {
-               if(dt>OB_WIRE && dt<OB_TEXTURE && (ob->mode & OB_MODE_EDIT)==0 && (flag & DRAW_SCENESET)==0) {
+       /* draw outline for selected objects, mesh does itself */
+       if((v3d->flag & V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && ob->type!=OB_MESH) {
+               if(dt>OB_WIRE && (ob->mode & OB_MODE_EDIT)==0 && (flag & DRAW_SCENESET)==0) {
                        if (!(ob->dtx&OB_DRAWWIRE) && (ob->flag&SELECT) && !(flag&DRAW_PICKING)) {
                                
-                               drawSolidSelect(scene, v3d, ar, base);
+                               drawObjectSelect(scene, v3d, ar, base);
                        }
                }
        }
@@ -5503,8 +5839,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                if (cu->linewidth != 0.0) {
                                        cpack(0xff44ff);
                                        UI_ThemeColor(TH_WIRE);
-                                       VECCOPY(vec1, ob->orig);
-                                       VECCOPY(vec2, ob->orig);
+                                       copy_v3_v3(vec1, ob->orig);
+                                       copy_v3_v3(vec2, ob->orig);
                                        vec1[0] += cu->linewidth;
                                        vec2[0] += cu->linewidth;
                                        vec1[1] += cu->linedist * cu->fsize;
@@ -5524,8 +5860,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                                        UI_ThemeColor(TH_ACTIVE);
                                                else
                                                        UI_ThemeColor(TH_WIRE);
-                                               vec1[0] = cu->tb[i].x;
-                                               vec1[1] = cu->tb[i].y + cu->fsize;
+                                               vec1[0] = (cu->xof * cu->fsize) + cu->tb[i].x;
+                                               vec1[1] = (cu->yof * cu->fsize) + cu->tb[i].y + cu->fsize;
                                                vec1[2] = 0.001;
                                                glBegin(GL_LINE_STRIP);
                                                glVertex3fv(vec1);
@@ -5570,9 +5906,11 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        set_inverted_drawing(0);
                                }
                        }
-                       else if(dt==OB_BOUNDBOX) 
-                               draw_bounding_volume(scene, ob);
-                       else if(boundbox_clip(rv3d, ob->obmat, cu->bb)) 
+                       else if(dt==OB_BOUNDBOX) {
+                               if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
+                                       draw_bounding_volume(scene, ob);
+                       }
+                       else if(boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb))
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
 
                        break;
@@ -5581,16 +5919,19 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        cu= ob->data;
 
                        if(cu->editnurb) {
-                               drawnurb(scene, v3d, rv3d, base, cu->editnurb->first, dt);
+                               ListBase *nurbs= ED_curve_editnurbs(cu);
+                               drawnurb(scene, v3d, rv3d, base, nurbs->first, dt);
+                       }
+                       else if(dt==OB_BOUNDBOX) {
+                               if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
+                                       draw_bounding_volume(scene, ob);
                        }
-                       else if(dt==OB_BOUNDBOX) 
-                               draw_bounding_volume(scene, ob);
-                       else if(boundbox_clip(rv3d, ob->obmat, cu->bb)) {
+                       else if(boundbox_clip(rv3d, ob->obmat, ob->bb ? ob->bb : cu->bb)) {
                                empty_object= drawDispList(scene, v3d, rv3d, base, dt);
-                               
-                               if(cu->path)
-                                       curve_draw_speed(scene, ob);
-                       }                       
+
+//XXX old animsys                              if(cu->path)
+//                                                     curve_draw_speed(scene, ob);
+                       }
                        break;
                case OB_MBALL:
                {
@@ -5598,51 +5939,69 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        
                        if(mb->editelems) 
                                drawmball(scene, v3d, rv3d, base, dt);
-                       else if(dt==OB_BOUNDBOX) 
-                               draw_bounding_volume(scene, ob);
+                       else if(dt==OB_BOUNDBOX) {
+                               if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
+                                       draw_bounding_volume(scene, ob);
+                       }
                        else 
                                empty_object= drawmball(scene, v3d, rv3d, base, dt);
                        break;
                }
                case OB_EMPTY:
-                       drawaxes(ob->empty_drawsize, flag, ob->empty_drawtype);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
+                               drawaxes(ob->empty_drawsize, ob->empty_drawtype);
                        break;
                case OB_LAMP:
-                       drawlamp(scene, v3d, rv3d, base, dt, flag);
-                       if(dtx || (base->flag & SELECT)) glMultMatrixf(ob->obmat);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
+                               drawlamp(scene, v3d, rv3d, base, dt, flag);
+                               if(dtx || (base->flag & SELECT)) glMultMatrixf(ob->obmat);
+                       }
                        break;
                case OB_CAMERA:
-                       drawcamera(scene, v3d, rv3d, ob, flag);
+                       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);
                        break;
                case OB_LATTICE:
-                       drawlattice(scene, v3d, ob);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
+                               drawlattice(scene, v3d, ob);
+                       }
                        break;
                case OB_ARMATURE:
-                       if(dt>OB_WIRE) GPU_enable_material(0, NULL); // we use default material
-                       empty_object= draw_armature(scene, v3d, ar, base, dt, flag);
-                       if(dt>OB_WIRE) GPU_disable_material();
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
+                               if(dt>OB_WIRE) GPU_enable_material(0, NULL); // we use default material
+                               empty_object= draw_armature(scene, v3d, ar, base, dt, flag);
+                               if(dt>OB_WIRE) GPU_disable_material();
+                       }
                        break;
                default:
-                       drawaxes(1.0, flag, OB_ARROWS);
+                       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
+                               drawaxes(1.0, OB_ARROWS);
+                       }
        }
-       if(ob->soft /*&& flag & OB_SBMOTION*/){
-               float mrt[3][3],msc[3][3],mtr[3][3]; 
-               SoftBody *sb = 0;
-               float tipw = 0.5f, tiph = 0.5f,drawsize = 4.0f;
-               if ((sb= ob->soft)){
-                       if(sb->solverflags & SBSO_ESTIMATEIPO){
 
-                               glLoadMatrixf(rv3d->viewmat);
-                               copy_m3_m3(msc,sb->lscale);
-                               copy_m3_m3(mrt,sb->lrot);
-                               mul_m3_m3m3(mtr,mrt,msc); 
-                               ob_draw_RE_motion(sb->lcom,mtr,tipw,tiph,drawsize);
-                               glMultMatrixf(ob->obmat);
+       if((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
+
+               if(ob->soft /*&& flag & OB_SBMOTION*/){
+                       float mrt[3][3],msc[3][3],mtr[3][3]; 
+                       SoftBody *sb = 0;
+                       float tipw = 0.5f, tiph = 0.5f,drawsize = 4.0f;
+                       if ((sb= ob->soft)){
+                               if(sb->solverflags & SBSO_ESTIMATEIPO){
+
+                                       glLoadMatrixf(rv3d->viewmat);
+                                       copy_m3_m3(msc,sb->lscale);
+                                       copy_m3_m3(mrt,sb->lrot);
+                                       mul_m3_m3m3(mtr,mrt,msc); 
+                                       ob_draw_RE_motion(sb->lcom,mtr,tipw,tiph,drawsize);
+                                       glMultMatrixf(ob->obmat);
+                               }
                        }
                }
-       }
 
-       if(ob->pd && ob->pd->forcefield) draw_forcefield(scene, ob, rv3d);
+               if(ob->pd && ob->pd->forcefield) {
+                       draw_forcefield(scene, ob, rv3d);
+               }
+       }
 
        /* code for new particle system */
        if(             (warning_recursive==0) &&
@@ -5651,7 +6010,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        (ob!=scene->obedit)     
          ) {
                ParticleSystem *psys;
-               PTCacheEdit *edit = PE_get_current(scene, ob);
 
                if(col || (ob->flag & SELECT)) cpack(0xFFFFFF); /* for visibility, also while wpaint */
                //glDepthMask(GL_FALSE);
@@ -5662,13 +6020,15 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
                for(psys=ob->particlesystem.first; psys; psys=psys->next) {
                        /* run this so that possible child particles get cached */
-                       if(ob->mode & OB_MODE_PARTICLE_EDIT && ob==OBACT)
+                       if(ob->mode & OB_MODE_PARTICLE_EDIT && ob==OBACT) {
+                               PTCacheEdit *edit = PE_create_current(scene, ob);
                                if(edit && edit->psys == psys)
                                        draw_update_ptcache_edit(scene, ob, edit);
+                       }
 
                        draw_new_particle_system(scene, v3d, rv3d, base, psys, dt);
                }
-               
+               invert_m4_m4(ob->imat, ob->obmat);
                view3d_cached_text_draw_end(v3d, ar, 0, NULL);
 
                glMultMatrixf(ob->obmat);
@@ -5684,10 +6044,11 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
          ) {
 
                if(ob->mode & OB_MODE_PARTICLE_EDIT && ob==OBACT) {
-                       PTCacheEdit *edit = PE_get_current(scene, ob);
+                       PTCacheEdit *edit = PE_create_current(scene, ob);
                        if(edit) {
                                glLoadMatrixf(rv3d->viewmat);
-                               draw_ptcache_edit(scene, v3d, rv3d, ob, edit, dt);
+                               draw_update_ptcache_edit(scene, ob, edit);
+                               draw_ptcache_edit(scene, v3d, edit);
                                glMultMatrixf(ob->obmat);
                        }
                }
@@ -5741,7 +6102,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 // #if 0
                                smd->domain->tex = NULL;
                                GPU_create_smoke(smd, 0);
-                               draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->p0, smd->domain->p1, smd->domain->res, smd->domain->dx, smd->domain->tex_shadow);
+                               draw_volume(ar, smd->domain->tex, smd->domain->p0, smd->domain->p1, smd->domain->res, smd->domain->dx, smd->domain->tex_shadow);
                                GPU_free_smoke(smd);
 // #endif
 #if 0
@@ -5769,7 +6130,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        if(density[index] > FLT_EPSILON)
                                        {
                                                float color[3];
-                                               VECCOPY(tmp, smd->domain->p0);
+                                               copy_v3_v3(tmp, smd->domain->p0);
                                                tmp[0] += smd->domain->dx * x + smd->domain->dx * 0.5;
                                                tmp[1] += smd->domain->dx * y + smd->domain->dx * 0.5;
                                                tmp[2] += smd->domain->dx * z + smd->domain->dx * 0.5;
@@ -5792,13 +6153,14 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        {
                                smd->domain->tex = NULL;
                                GPU_create_smoke(smd, 1);
-                               draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->p0, smd->domain->p1, smd->domain->res_wt, smd->domain->dx_wt, smd->domain->tex_shadow);
+                               draw_volume(ar, smd->domain->tex, smd->domain->p0, smd->domain->p1, smd->domain->res_wt, smd->domain->dx_wt, smd->domain->tex_shadow);
                                GPU_free_smoke(smd);
                        }
                }
        }
 
-       {
+       if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
+
                bConstraint *con;
                for(con=ob->constraints.first; con; con= con->next) 
                {
@@ -5809,32 +6171,36 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                                        drawRBpivot(data);
                        }
                }
-       }
 
-       /* draw extra: after normal draw because of makeDispList */
-       if(dtx && !(G.f & (G_RENDER_OGL|G_RENDER_SHADOW))) {
-               if(dtx & OB_AXIS) {
-                       drawaxes(1.0f, flag, OB_ARROWS);
-               }
-               if(dtx & OB_BOUNDBOX) draw_bounding_volume(scene, ob);
-               if(dtx & OB_TEXSPACE) drawtexspace(ob);
-               if(dtx & OB_DRAWNAME) {
-                       /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
-                       /* but, we also dont draw names for sets or duplicators */
-                       if(flag == 0) {
-                               view3d_cached_text_draw_add(0.0f, 0.0f, 0.0f, ob->id.name+2, 10, 0);
+               /* draw extra: after normal draw because of makeDispList */
+               if(dtx && (G.f & G_RENDER_OGL)==0) {
+
+                       if(dtx & OB_AXIS) {
+                               drawaxes(1.0f, OB_ARROWS);
+                       }
+                       if(dtx & OB_BOUNDBOX) {
+                               if((v3d->flag2 & V3D_RENDER_OVERRIDE)==0)
+                                       draw_bounding_volume(scene, ob);
+                       }
+                       if(dtx & OB_TEXSPACE) drawtexspace(ob);
+                       if(dtx & OB_DRAWNAME) {
+                               /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
+                               /* but, we also dont draw names for sets or duplicators */
+                               if(flag == 0) {
+                                       float zero[3]= {0,0,0};
+                                       view3d_cached_text_draw_add(zero, ob->id.name+2, 10, 0);
+                               }
                        }
+                       /*if(dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
+                       if((dtx & OB_DRAWWIRE) && dt>=OB_SOLID) drawWireExtra(scene, rv3d, ob);
                }
-               /*if(dtx & OB_DRAWIMAGE) drawDispListwire(&ob->disp);*/
-               if((dtx & OB_DRAWWIRE) && dt>=OB_SOLID) drawWireExtra(scene, rv3d, ob);
        }
 
-       if(dt<OB_SHADED) {
+       if(dt<OB_SHADED && (v3d->flag2 & V3D_RENDER_OVERRIDE)==0) {
                if((ob->gameflag & OB_DYNAMIC) || 
                        ((ob->gameflag & OB_BOUNDS) && (ob->boundtype == OB_BOUND_SPHERE))) {
-                       float imat[4][4], vec[3];
+                       float imat[4][4], vec[3]= {0.0f, 0.0f, 0.0f};
 
-                       vec[0]= vec[1]= vec[2]= 0.0;
                        invert_m4_m4(imat, rv3d->viewmatob);
 
                        setlinestyle(2);
@@ -5844,6 +6210,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
        }
        
        /* return warning, this is cached text draw */
+       invert_m4_m4(ob->imat, ob->obmat);
        view3d_cached_text_draw_end(v3d, ar, 1, NULL);
 
        glLoadMatrixf(rv3d->viewmat);
@@ -5852,13 +6219,15 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
        if(warning_recursive) return;
        if(base->flag & OB_FROMDUPLI) return;
-       if(G.f & G_RENDER_SHADOW) return;
+       if(v3d->flag2 & V3D_RENDER_OVERRIDE) return;
 
        /* object centers, need to be drawn in viewmat space for speed, but OK for picking select */
        if(ob!=OBACT || !(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT))) {
                int do_draw_center= -1; /* defines below are zero or positive... */
 
-               if((scene->basact)==base) 
+               if(v3d->flag2 & V3D_RENDER_OVERRIDE) {
+                       /* dont draw */
+               } else if((scene->basact)==base)
                        do_draw_center= ACTIVE;
                else if(base->flag & SELECT) 
                        do_draw_center= SELECT;
@@ -5875,15 +6244,15 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        else if((flag & DRAW_CONSTCOLOR)==0) {
                                /* we don't draw centers for duplicators and sets */
                                if(U.obcenter_dia > 0) {
-                    /* check > 0 otherwise grease pencil can draw into the circle select which is annoying. */
-                    drawcentercircle(v3d, rv3d, ob->obmat[3], do_draw_center, ob->id.lib || ob->id.us>1);
+                                       /* check > 0 otherwise grease pencil can draw into the circle select which is annoying. */
+                                       drawcentercircle(v3d, rv3d, ob->obmat[3], do_draw_center, ob->id.lib || ob->id.us>1);
                                }
                        }
                }
        }
 
        /* not for sets, duplicators or picking */
-       if(flag==0 && (!(v3d->flag & V3D_HIDE_HELPLINES))) {
+       if(flag==0 && (v3d->flag & V3D_HIDE_HELPLINES)== 0 && (v3d->flag2 & V3D_RENDER_OVERRIDE)== 0) {
                ListBase *list;
                
                /* draw hook center and offset line */
@@ -5904,10 +6273,10 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                if (list) {
                        bConstraint *curcon;
                        bConstraintOb *cob;
-                       char col[4], col2[4];
+                       char col1[4], col2[4];
                        
-                       UI_GetThemeColor3ubv(TH_GRID, col);
-                       UI_make_axis_color(col, col2, 'z');
+                       UI_GetThemeColor3ubv(TH_GRID, col1);
+                       UI_make_axis_color(col1, col2, 'z');
                        glColor3ubv((GLubyte *)col2);
                        
                        cob= constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
@@ -5949,7 +6318,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 
 /* ***************** BACKBUF SEL (BBS) ********* */
 
-static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
        int offset = (intptr_t) userData;
        EditVert *eve = EM_get_vert_for_index(index);
@@ -5985,7 +6354,7 @@ static void bbs_mesh_wire(DerivedMesh *dm, int offset)
        dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, (void*)(intptr_t) offset);
 }              
 
-static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index, int *drawSmooth_r)
+static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r))
 {
        if (EM_get_face_for_index(index)->h==0) {
                if (userData) {
@@ -5997,7 +6366,7 @@ static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index, int *d
        }
 }
 
-static void bbs_mesh_solid__drawCenter(void *userData, int index, float *cent, float *no)
+static void bbs_mesh_solid__drawCenter(void *UNUSED(userData), int index, float *cent, float *UNUSED(no))
 {
        EditFace *efa = EM_get_face_for_index(index);
 
@@ -6014,9 +6383,9 @@ static void bbs_mesh_solid_EM(Scene *scene, View3D *v3d, Object *ob, DerivedMesh
        cpack(0);
 
        if (facecol) {
-               dm->drawMappedFaces(dm, bbs_mesh_solid__setSolidDrawOptions, (void*)(intptr_t) 1, 0);
+               dm->drawMappedFaces(dm, bbs_mesh_solid__setSolidDrawOptions, (void*)(intptr_t) 1, 0, GPU_enable_material);
 
-               if( CHECK_OB_DRAWFACEDOT(scene, v3d, ob->dt) ) {
+               if(check_ob_drawface_dot(scene, v3d, ob->dt)) {
                        glPointSize(UI_GetThemeValuef(TH_FACEDOT_SIZE));
                
                        bglBegin(GL_POINTS);
@@ -6025,17 +6394,17 @@ static void bbs_mesh_solid_EM(Scene *scene, View3D *v3d, Object *ob, DerivedMesh
                }
 
        } else {
-               dm->drawMappedFaces(dm, bbs_mesh_solid__setSolidDrawOptions, (void*) 0, 0);
+               dm->drawMappedFaces(dm, bbs_mesh_solid__setSolidDrawOptions, (void*) 0, 0, GPU_enable_material);
        }
 }
 
-static int bbs_mesh_solid__setDrawOpts(void *userData, int index, int *drawSmooth_r)
+static int bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index, int *UNUSED(drawSmooth_r))
 {
        WM_set_framebuffer_index_color(index+1);
        return 1;
 }
 
-static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *drawSmooth_r)
+static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r))
 {
        Mesh *me = userData;
 
@@ -6055,8 +6424,8 @@ static void bbs_mesh_solid(Scene *scene, View3D *v3d, Object *ob)
        
        glColor3ub(0, 0, 0);
                
-       if(face_sel_mode)       dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, me, 0);
-       else                            dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, me, 0);
+       if(face_sel_mode)       dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, me, 0, GPU_enable_material);
+       else                            dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, me, 0, GPU_enable_material);
 
        dm->release(dm);
 }
@@ -6136,9 +6505,9 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *r
 
        if(dt<=OB_WIRE) {
                if(dm)
-                       dm->drawEdges(dm, 1);
+                       dm->drawEdges(dm, 1, 0);
                else if(edm)
-                       edm->drawEdges(edm, 1); 
+                       edm->drawEdges(edm, 1, 0);      
        }
        else {
                if(outline)
@@ -6163,7 +6532,7 @@ static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *r
                        GPU_end_object_materials();
                }
                else if(edm)
-                       edm->drawMappedFaces(edm, NULL, NULL, 0);
+                       edm->drawMappedFaces(edm, NULL, NULL, 0, GPU_enable_material);
                
                glDisable(GL_LIGHTING);
        }
@@ -6182,7 +6551,7 @@ void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object
                        draw_object_mesh_instance(scene, v3d, rv3d, ob, dt, outline);
                        break;
                case OB_EMPTY:
-                       drawaxes(ob->empty_drawsize, 0, ob->empty_drawtype);
+                       drawaxes(ob->empty_drawsize, ob->empty_drawtype);
                        break;
        }
 }