diff options
author | Ton Roosendaal <ton@blender.org> | 2004-09-26 17:45:25 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2004-09-26 17:45:25 +0400 |
commit | d41317609df89fee5e8d743afb6866e29ceb388f (patch) | |
tree | e0c02a76a1c6b150feb142adf8b600a4208cbf8d /source | |
parent | 9a6b8971dcb29e078acd5de7b0b70df5e6147fb0 (diff) |
Added initialize code for zbuffer-select option, where it reads larger
parts of zbuffer on border/circle select.
Should speed up quite some.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/include/BIF_editmesh.h | 3 | ||||
-rw-r--r-- | source/blender/src/edit.c | 20 | ||||
-rw-r--r-- | source/blender/src/editmesh_mods.c | 49 | ||||
-rw-r--r-- | source/blender/src/editview.c | 190 |
4 files changed, 70 insertions, 192 deletions
diff --git a/source/blender/include/BIF_editmesh.h b/source/blender/include/BIF_editmesh.h index 2e63026a91d..854fe3aa654 100644 --- a/source/blender/include/BIF_editmesh.h +++ b/source/blender/include/BIF_editmesh.h @@ -91,7 +91,10 @@ extern void vertexnormals(int testflip); /* ******************* editmesh_mods.c */ extern void EM_select_face_fgon(struct EditFace *efa, int sel); + extern int EM_zbuffer_visible(float *co, short xs, short ys); +extern void EM_set_zbufselect_cache(short minx, short miny, short maxx, short maxy); +extern void EM_free_zbufselect_cache(void); extern void vertexnoise(void); extern void vertexsmooth(void); diff --git a/source/blender/src/edit.c b/source/blender/src/edit.c index 8843d6475a5..ccb5f988da3 100644 --- a/source/blender/src/edit.c +++ b/source/blender/src/edit.c @@ -46,6 +46,8 @@ #include "BMF_Api.h" +#include "PIL_time.h" + #include "DNA_armature_types.h" #include "DNA_curve_types.h" #include "DNA_lattice_types.h" @@ -333,7 +335,7 @@ void draw_sel_circle(short *mval, short *mvalo, float rad, float rado, int selec { static short no_mvalo=0; - if(mval==0 && mvalo==0) { /* signal */ + if(mval==NULL && mvalo==NULL) { /* signal */ no_mvalo= 1; return; } @@ -375,9 +377,12 @@ void circle_selectCB(select_CBfunc callback) if(G.obedit) obj = G.obedit; else obj = OBACT; + mywinset(curarea->win); getmouseco_areawin(mvalo); - draw_sel_circle(mvalo, 0, rad, 0.0, selecting); + mval[0]= mvalo[0]; mval[1]= mvalo[1]; + + draw_sel_circle(mval, NULL, rad, 0.0, selecting); rado= rad; @@ -385,10 +390,8 @@ void circle_selectCB(select_CBfunc callback) /* for when another window is open and a mouse cursor activates it */ - mywinset(curarea->win); + //mywinset(curarea->win); - getmouseco_areawin(mval); - if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || rado!=rad || firsttime) { firsttime= 0; @@ -403,11 +406,15 @@ void circle_selectCB(select_CBfunc callback) rado= rad; } + event= extern_qread(&val); if (event) { int afbreek= 0; + + getmouseco_areawin(mval); // important to do here, trust events! switch(event) { + case LEFTMOUSE: case MIDDLEMOUSE: if(val) selecting= event; @@ -433,10 +440,11 @@ void circle_selectCB(select_CBfunc callback) if(afbreek) break; } + else PIL_sleep_ms(10); } /* clear circle */ - draw_sel_circle(0, mvalo, 0, rad, 1); + draw_sel_circle(NULL, mvalo, 0, rad, 1); BIF_undo_push("Circle Select"); countall(); allqueue(REDRAWINFO, 0); diff --git a/source/blender/src/editmesh_mods.c b/source/blender/src/editmesh_mods.c index 98b6fb3e7ec..89227db1af4 100644 --- a/source/blender/src/editmesh_mods.c +++ b/source/blender/src/editmesh_mods.c @@ -99,6 +99,48 @@ editmesh_mods.c, UI level access, no geometry changes /* ****************************** SELECTION ROUTINES **************** */ +// caching + +static unsigned int *zbuffer= NULL; +static short zminx, zminy, zmaxx, zmaxy; + +void EM_set_zbufselect_cache(short minx, short miny, short maxx, short maxy) +{ + + if(G.vd->drawtype<OB_SOLID || (G.vd->flag & V3D_ZBUF_SELECT)==0) return; + + if(minx<0) minx= 0; + if(miny<0) miny= 0; + if(maxx>=curarea->winx) maxx= curarea->winx; + if(maxy>=curarea->winy) maxy= curarea->winy; + + if(minx<=maxx && miny<=maxy) { + zbuffer= MEM_mallocN( (maxx-minx+1)*(maxy-miny+1)*sizeof(int), "zbuffer select"); + glReadPixels(curarea->winrct.xmin+minx, curarea->winrct.ymin+miny, (maxx-minx+1), (maxy-miny+1), + GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, zbuffer); + zminx= minx; zminy= miny; + zmaxx= maxx; zmaxy= maxy; + } +} + +void EM_free_zbufselect_cache(void) +{ + if(zbuffer) MEM_freeN(zbuffer); + zbuffer= NULL; +} + +static void myglReadPixels(short xs, short ys, unsigned int *data) +{ + + if(zbuffer) { + if(xs<zminx || xs>zmaxx || ys<zminy || ys>zmaxy) *data= 0xFFFFFFFF; + else *data= zbuffer[ (zmaxx-zminx+1)*(ys-zminy) + (xs-zminx) ]; + } + else + glReadPixels(curarea->winrct.xmin+xs, curarea->winrct.ymin+ys, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, data); + +} + /* return 1 if visible */ int EM_zbuffer_visible(float *co, short xs, short ys) { @@ -119,8 +161,7 @@ int EM_zbuffer_visible(float *co, short xs, short ys) Mat4MulMat4(persmat, vmat, pmat); bglPolygonOffset(0.0); // restores proj matrix - myloadmatrix(G.vd->viewmat); - + myloadmatrix(G.vd->viewmat); return 0; } @@ -135,7 +176,9 @@ int EM_zbuffer_visible(float *co, short xs, short ys) if(1) { unsigned int zvali; - glReadPixels(curarea->winrct.xmin+xs, curarea->winrct.ymin+ys, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &zvali); + + myglReadPixels(xs, ys, &zvali); + // glReadPixels(curarea->winrct.xmin+xs, curarea->winrct.ymin+ys, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &zvali); zval= ((float)zvali)/((float)0xFFFFFFFF); // printf("my proj %f zbuf %x %f mydiff %f\n", vec4[2], zvali, zval, vec4[2]-zval); } diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index 567c11d8c7f..64b4201e15b 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -794,6 +794,7 @@ void borderselect(void) EditFace *efa; EM_zbuffer_visible(NULL, 0, 0); // init + EM_set_zbufselect_cache(rect.xmin, rect.ymin, rect.xmax, rect.ymax); if(G.scene->selectmode & SCE_SELECT_VERTEX) { calc_meshverts_ext(); /* clips, drawobject.c */ @@ -854,6 +855,8 @@ void borderselect(void) } } + EM_free_zbufselect_cache(); + EM_selectmode_flush(); allqueue(REDRAWVIEW3D, 0); @@ -1054,8 +1057,10 @@ void mesh_selectionCB(int selecting, Object *editobj, short *mval, float rad) EditEdge *eed; EditFace *efa; float x, y, r; + short rads= (short)(rad+1.0); EM_zbuffer_visible(NULL, 0, 0); // init + EM_set_zbufselect_cache(mval[0]-rads, mval[1]-rads, mval[0]+rads, mval[1]+rads); if(G.scene->selectmode & SCE_SELECT_VERTEX) { calc_meshverts_ext(); /* drawobject.c */ @@ -1108,7 +1113,8 @@ void mesh_selectionCB(int selecting, Object *editobj, short *mval, float rad) } } } - + + EM_free_zbufselect_cache(); EM_selectmode_flush(); draw_sel_circle(0, 0, 0, 0, 0); /* signal */ @@ -1228,188 +1234,6 @@ void obedit_selectionCB(short selecting, Object *editobj, short *mval, float rad } } -/** The circle select function - should be replaced by the callback - * version circle_selectCB(). Why ? Because it's not nice as it is! - * - */ - -void circle_select(void) -{ - EditMesh *em = G.editMesh; - Nurb *nu; - BPoint *bp; - BezTriple *bezt; - EditVert *eve; - static float rad= 40.0; - float rado, x, y, trad; - int a, firsttime=1; - unsigned short event; - short mvalo[2], mval[2], val; - short selecting=0; - - if(G.obedit==0) return; - - getmouseco_areawin(mvalo); - draw_sel_circle(mvalo, 0, rad, 0.0, selecting); - - rado= rad; - - while(TRUE) { - - /* when a renderwindow is open and mouse enters it (activates sometimes) */ - - mywinset(curarea->win); - - getmouseco_areawin(mval); - - if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || rado!=rad || firsttime) { - firsttime= 0; - - draw_sel_circle(mval, mvalo, rad, rado, selecting); - - mvalo[0]= mval[0]; - mvalo[1]= mval[1]; - rado= rad; - - if(selecting) { - - if(G.obedit->type==OB_MESH) { - - calc_meshverts_ext(); /* drawobject.c */ - eve= em->verts.first; - while(eve) { - if(eve->h==0) { - x= eve->xs-mval[0]; - y= eve->ys-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) eve->f|= 1; - else eve->f&= 254; - } - } - eve= eve->next; - } - draw_sel_circle(0, 0, 0, 0, 0); /* signal */ - force_draw(); - } - else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) { - - calc_nurbverts_ext(); /* drawobject.c */ - nu= editNurb.first; - while(nu) { - if((nu->type & 7)==CU_BEZIER) { - bezt= nu->bezt; - a= nu->pntsu; - while(a--) { - if(bezt->hide==0) { - x= bezt->s[0][0]-mval[0]; - y= bezt->s[0][1]-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) bezt->f1|= 1; - else bezt->f1 &= ~1; - } - x= bezt->s[1][0]-mval[0]; - y= bezt->s[1][1]-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) bezt->f2|= 1; - else bezt->f2 &= ~1; - } - x= bezt->s[2][0]-mval[0]; - y= bezt->s[2][1]-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) bezt->f3|= 1; - else bezt->f3 &= ~1; - } - - } - bezt++; - } - } - else { - bp= nu->bp; - a= nu->pntsu*nu->pntsv; - while(a--) { - if(bp->hide==0) { - x= bp->s[0]-mval[0]; - y= bp->s[1]-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) bp->f1|= 1; - else bp->f1 &= ~1; - } - } - bp++; - } - } - nu= nu->next; - } - draw_sel_circle(0, 0, 0, 0, 0); /* signal */ - force_draw(); - } - else if(G.obedit->type==OB_LATTICE) { - calc_lattverts_ext(); - - bp= editLatt->def; - - a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; - while(a--) { - if(bp->hide==0) { - x= bp->s[0]-mval[0]; - y= bp->s[1]-mval[1]; - trad= sqrt(x*x+y*y); - if(trad<=rad) { - if(selecting==LEFTMOUSE) bp->f1|= 1; - else bp->f1 &= ~1; - } - } - bp++; - } - draw_sel_circle(0, 0, 0, 0, 0); /* signal */ - force_draw(); - } - } - } - - event= extern_qread(&val); - if (event) { - int afbreek= 0; - - switch(event) { - case LEFTMOUSE: - case MIDDLEMOUSE: - if(val) selecting= event; - else selecting= 0; - firsttime= 1; - - break; - case PADPLUSKEY: - if(val) if(rad<200.0) rad*= 1.2; - break; - case PADMINUS: - if(val) if(rad>5.0) rad/= 1.2; - break; - - case ESCKEY: case SPACEKEY: case RIGHTMOUSE: - case GKEY: case SKEY: case RKEY: case XKEY: case EKEY: case TABKEY: - afbreek= 1; - break; - - } - - if(afbreek) break; - } - } - - /* clear circle */ - draw_sel_circle(0, mvalo, 0, rad, 1); - - countall(); - allqueue(REDRAWINFO, 0); -} - void set_render_border(void) { rcti rect; |