diff options
author | Ton Roosendaal <ton@blender.org> | 2006-02-08 19:51:09 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2006-02-08 19:51:09 +0300 |
commit | 839b338be35dd11d30231d1dee1a3454b952ab55 (patch) | |
tree | 6bb9375175ad26f7135adef188a9ca7358b667b5 | |
parent | 10acbf00abc679855184da750d295d1115bb515c (diff) |
New:
- ZTransp render now also delivers Z values and Speed vectors in passes
Note that speed vectors accumulate within a pixel to store the minimum,
so rendering ztransp on top of a non-moving plane won't give speed...
Best results you get is by rendering it in a separate layer.
The Z value stored is the closest visible transparent face in the pixel.
Fixes:
- Render to 'spare page' has been enabled again. Because of the strict
separation of Render and UI, but especially because a 'render result' now
can consist of unlimited images, I've not made this a Render feature.
Instead, the render-window itself stores the 'spare' image... I also
had to change the convention for it a bit.
Now, instead of having two "render buffers" (which was a render feature),
the RenderWindow will store each previous frame on a re-render. This
storing will only start after you've pressed 'Jkey' once, but then always
will happen for as long the rendered image is same size as previously.
For clarity, I've also renamed the window title, to 'previous frame'.
- RenderWindow shows alpha again on Akey
- Display of the Zvalues in ImageWindow has been tweaked. White now denotes
closest, and the color range goes from camera clip-sta to clip-end.
- Bugfix: on splitting/merging/duplicating windows, the 3D Previewrender was
not always freed correctly, potentially causing crashes or memory leaks.
-rw-r--r-- | source/blender/include/BIF_previewrender.h | 3 | ||||
-rw-r--r-- | source/blender/render/intern/include/renderpipeline.h | 1 | ||||
-rw-r--r-- | source/blender/render/intern/include/zbuf.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/pipeline.c | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 34 | ||||
-rw-r--r-- | source/blender/render/intern/source/zbuf.c | 142 | ||||
-rw-r--r-- | source/blender/src/drawimage.c | 18 | ||||
-rw-r--r-- | source/blender/src/drawview.c | 2 | ||||
-rw-r--r-- | source/blender/src/previewrender.c | 8 | ||||
-rw-r--r-- | source/blender/src/renderwin.c | 135 | ||||
-rw-r--r-- | source/blender/src/space.c | 20 | ||||
-rw-r--r-- | source/blender/src/toets.c | 1 |
12 files changed, 273 insertions, 95 deletions
diff --git a/source/blender/include/BIF_previewrender.h b/source/blender/include/BIF_previewrender.h index dec85f5f6e7..b2dccc894f6 100644 --- a/source/blender/include/BIF_previewrender.h +++ b/source/blender/include/BIF_previewrender.h @@ -32,6 +32,7 @@ #include "DNA_vec_types.h" +struct View3D; struct SpaceButs; struct RenderInfo; struct Image; @@ -83,6 +84,6 @@ void BIF_preview_free_dbase (void); void BIF_view3d_previewrender(struct ScrArea *sa); void BIF_view3d_previewdraw (struct ScrArea *sa, struct uiBlock *block); -void BIF_view3d_previewrender_free(struct ScrArea *sa); +void BIF_view3d_previewrender_free(struct View3D *v3d); void BIF_view3d_previewrender_clear(struct ScrArea *sa); void BIF_view3d_previewrender_signal(struct ScrArea *sa, short signal); diff --git a/source/blender/render/intern/include/renderpipeline.h b/source/blender/render/intern/include/renderpipeline.h index 5ccb2f318dc..400420c7081 100644 --- a/source/blender/render/intern/include/renderpipeline.h +++ b/source/blender/render/intern/include/renderpipeline.h @@ -36,6 +36,7 @@ void *RE_mallocN(int len, char *name); void *RE_callocN(int len, char *name); void RE_freeN(void *poin); +#define PASS_VECTOR_MAX 10000.0f #endif /* PIPELINE_H */ diff --git a/source/blender/render/intern/include/zbuf.h b/source/blender/render/intern/include/zbuf.h index 82455088565..3a9a9113fe2 100644 --- a/source/blender/render/intern/include/zbuf.h +++ b/source/blender/render/intern/include/zbuf.h @@ -49,7 +49,7 @@ int testclip(float *v); void set_part_zbuf_clipflag(struct RenderPart *pa); void zbuffer_shadow(struct Render *re, struct LampRen *lar, int *rectz, int size); void zbuffer_solid(struct RenderPart *pa, unsigned int layer, short layflag); -void zbuffer_transp_shade(struct RenderPart *pa, float *pass, unsigned int layer, short layflag); +void zbuffer_transp_shade(struct RenderPart *pa, struct RenderLayer *rl, float *pass); void convert_zbuf_to_distbuf(struct RenderPart *pa, struct RenderLayer *rl); typedef struct APixstr { diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 431df31279e..c6b14ad0037 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -189,7 +189,7 @@ static void render_layer_add_pass(RenderLayer *rl, int rectsize, int passtype, c /* initialize to max speed */ rect= rpass->rect= RE_mallocN(sizeof(float)*rectsize, mallocstr); for(x= rectsize-1; x>=0; x--) - rect[x]= 10000.0f; + rect[x]= PASS_VECTOR_MAX; } else rpass->rect= RE_callocN(sizeof(float)*rectsize, mallocstr); diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index b3ecb92a12d..d7fdc15e4e4 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2687,6 +2687,30 @@ static void edge_enhance_add(RenderPart *pa, float *rectf, float *arect) /* ********************* MAINLOOPS ******************** */ +static void reset_sky_speedvectors(RenderPart *pa, RenderLayer *rl) +{ + + /* speed vector exception... if solid render was done, sky pixels are set to zero already */ + /* for all pixels with alpha zero, we re-initialize speed again then */ + if(rl->layflag & SCE_LAY_SOLID) { + float *fp, *col; + int a; + + fp= RE_RenderLayerGetPass(rl, SCE_PASS_VECTOR); + if(fp==NULL) return; + col= rl->rectf+3; + + for(a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) { + if(col[a]==0.0f) { + fp[a]= PASS_VECTOR_MAX; + fp[a+1]= PASS_VECTOR_MAX; + fp[a+2]= PASS_VECTOR_MAX; + fp[a+3]= PASS_VECTOR_MAX; + } + } + } +} + /* osa version */ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, ShadeResult *shr) { @@ -3050,9 +3074,12 @@ void zbufshadeDA_tile(RenderPart *pa) float *fcol= rl->rectf, *acol= acolrect; int x; + if(rl->passflag & SCE_PASS_VECTOR) + reset_sky_speedvectors(pa, rl); + /* swap for live updates */ SWAP(float *, acolrect, rl->rectf); - zbuffer_transp_shade(pa, rl->rectf, rl->lay, rl->layflag); + zbuffer_transp_shade(pa, rl, rl->rectf); SWAP(float *, acolrect, rl->rectf); for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { @@ -3151,9 +3178,12 @@ void zbufshade_tile(RenderPart *pa) float *fcol= rl->rectf, *acol= acolrect; int x; + if(addpassflag & SCE_PASS_VECTOR) + reset_sky_speedvectors(pa, rl); + /* swap for live updates */ SWAP(float *, acolrect, rl->rectf); - zbuffer_transp_shade(pa, rl->rectf, rl->lay, rl->layflag); + zbuffer_transp_shade(pa, rl, rl->rectf); SWAP(float *, acolrect, rl->rectf); for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) { diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index aa935e1815a..bc77813d59a 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -2258,7 +2258,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float * v3[0]= speedfac*dz2[5]+fx+1.0f; v3[1]= speedfac*dz2[6]+fy+1.0f; v3[2]= dz2[z+5]; v4[0]= speedfac*dz2[0]+fx; v4[1]= speedfac*dz2[1]+fy+1.0f; v4[2]= dz2[z]; - zbuf_fill_in_rgba(&zspan, dimg, alpha, v1, v2, v3, v4); + zbuf_fill_in_rgba(&zspan, dimg, alpha*dimg[3], v1, v2, v3, v4); } } dz1+=5; @@ -2346,7 +2346,7 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int sample) * Do accumulation z buffering. */ -static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, unsigned int lay, short layflag) +static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, unsigned int lay) { ZSpan zspan; Material *ma=NULL; @@ -2451,6 +2451,72 @@ static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, u } +/* different rules for transparent pass... */ +/* if shr is zero, we clear winspeed if it's initialized to max still */ +static void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr) +{ + RenderPass *rpass; + + for(rpass= rl->passes.first; rpass; rpass= rpass->next) { + float *fp, *col= NULL; + int a, pixsize= 3; + + switch(rpass->passtype) { + case SCE_PASS_RGBA: + if(shr) col= shr->col; + pixsize= 4; + break; + case SCE_PASS_DIFFUSE: + if(shr) col= shr->diff; + break; + case SCE_PASS_SPEC: + if(shr) col= shr->spec; + break; + case SCE_PASS_SHADOW: + if(shr) col= shr->shad; + break; + case SCE_PASS_AO: + if(shr) col= shr->ao; + break; + case SCE_PASS_RAY: + if(shr) col= shr->ray; + break; + case SCE_PASS_NORMAL: + if(shr) col= shr->nor; + break; + case SCE_PASS_VECTOR: + { + fp= rpass->rect + 4*offset; + if(shr) { + /* add minimum speed in pixel */ + if( (ABS(shr->winspeed[0]) + ABS(shr->winspeed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) { + fp[0]= shr->winspeed[0]; + fp[1]= shr->winspeed[1]; + } + if( (ABS(shr->winspeed[2]) + ABS(shr->winspeed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) { + fp[2]= shr->winspeed[2]; + fp[3]= shr->winspeed[3]; + } + } + else { + /* clear */ + if(fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f; + if(fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f; + if(fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f; + if(fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f; + } + } + break; + } + if(col) { + fp= rpass->rect + pixsize*offset; + for(a=0; a<pixsize; a++) + fp[a]= col[a]; + } + } +} + + static int vergzvlak(const void *a1, const void *a2) { const int *x1=a1, *x2=a2; @@ -2463,7 +2529,7 @@ static int vergzvlak(const void *a1, const void *a2) /** * Shade this face at this location in SCS. */ -static void shadetrapixel(ShadePixelInfo *shpi, float x, float y, int z, int facenr, int mask, float *fcol) +static void shadetrapixel(ShadePixelInfo *shpi, float x, float y, int z, int facenr, int mask) { float rco[3]; @@ -2488,22 +2554,20 @@ static void shadetrapixel(ShadePixelInfo *shpi, float x, float y, int z, int fac } } tot= 1.0/tot; - fcol[0]= accumcol[0]*tot; - fcol[1]= accumcol[1]*tot; - fcol[2]= accumcol[2]*tot; - fcol[3]= accumcol[3]*tot; + shpi->shr.combined[0]= accumcol[0]*tot; + shpi->shr.combined[1]= accumcol[1]*tot; + shpi->shr.combined[2]= accumcol[2]*tot; + shpi->shr.combined[3]= accumcol[3]*tot; } else { int b= R.samples->centmask[mask]; x= x+R.samples->centLut[b & 15]; y= y+R.samples->centLut[b>>4]; shadepixel(shpi, x, y, z, facenr, mask, rco); - QUATCOPY(fcol, shpi->shr.combined); } } else { shadepixel(shpi, x, y, z, facenr, mask, rco); - QUATCOPY(fcol, shpi->shr.combined); } } @@ -2522,17 +2586,17 @@ static int addtosampcol(float *sampcol, float *fcol, int mask) #define MAX_ZROW 1000 /* main render call to fill in pass the full transparent layer */ -void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short layflag) +void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass) { RenderResult *rr= pa->result; ShadePixelInfo shpi; APixstr *APixbuf; /* Zbuffer: linked list of face samples */ APixstr *ap, *aprect, *apn; ListBase apsmbase={NULL, NULL}; - float fcol[4], sampcol[16*4]; + float sampcol[16*4]; float fac, alpha[32], *passrect= pass; int x, y, crop=0, a, zrow[MAX_ZROW][3], totface; - int sval; + int sval, addpassflag, offs= 0, od, addzbuf; /* looks nicer for calling code */ if(R.test_break()) @@ -2548,9 +2612,14 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l /* fill shadepixel info struct */ shpi.thread= pa->thread; - shpi.lay= lay; + shpi.lay= rl->lay; shpi.passflag= 0; + if(rl->passflag & ~(SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR|SCE_PASS_COMBINED)) + shpi.passflag= rl->passflag; + addpassflag= rl->passflag & ~(SCE_PASS_Z|SCE_PASS_COMBINED); + addzbuf= rl->passflag & SCE_PASS_Z; + /* alpha LUT */ if(R.osa) { fac= (1.0/(float)R.osa); @@ -2560,7 +2629,7 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l } /* fill the Apixbuf */ - zbuffer_abuf(pa, APixbuf, &apsmbase, lay, layflag); + zbuffer_abuf(pa, APixbuf, &apsmbase, rl->lay); aprect= APixbuf; /* filtered render, for now we assume only 1 filter size */ @@ -2568,6 +2637,7 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l crop= 1; passrect+= 4*(pa->rectx + 1); aprect+= pa->rectx + 1; + offs= pa->rectx + 1; } /* init scanline updates */ @@ -2579,10 +2649,15 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { pass= passrect; ap= aprect; - - for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, pass+=4) { - - if(ap->p[0]) { + od= offs; + + for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, pass+=4, od++) { + + if(ap->p[0]==NULL) { + if(addpassflag) + add_transp_passes(rl, od, NULL); + } + else { /* sort in z */ totface= 0; apn= ap; @@ -2602,14 +2677,19 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l if(totface==1) { - shadetrapixel(&shpi, (float)x, (float)y, zrow[0][0], zrow[0][1], zrow[0][2], fcol); + shadetrapixel(&shpi, (float)x, (float)y, zrow[0][0], zrow[0][1], zrow[0][2]); if(R.osa) { - add_filt_fmask(zrow[0][2], fcol, pass, rr->rectx); + add_filt_fmask(zrow[0][2], shpi.shr.combined, pass, rr->rectx); } else { - QUATCOPY(pass, fcol); + QUATCOPY(pass, shpi.shr.combined); } + if(addpassflag) + add_transp_passes(rl, od, &shpi.shr); + if(addzbuf) + if(pa->rectz[od]>zrow[0][0]) + pa->rectz[od]= zrow[0][0]; } else { @@ -2625,13 +2705,19 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l qsort(zrow, totface, sizeof(int)*3, vergzvlak); } + if(addzbuf) + if(pa->rectz[od]>zrow[totface-1][0]) + pa->rectz[od]= zrow[totface-1][0]; + if(R.osa==0) { while(totface>0) { totface--; - shadetrapixel(&shpi, (float)x, (float)y, zrow[totface][0], zrow[totface][1], zrow[totface][2], fcol); - addAlphaUnderFloat(pass, fcol); - + shadetrapixel(&shpi, (float)x, (float)y, zrow[totface][0], zrow[totface][1], zrow[totface][2]); + addAlphaUnderFloat(pass, shpi.shr.combined); + if(addpassflag) + add_transp_passes(rl, od, &shpi.shr); + if(pass[3]>=0.999) break; } } @@ -2642,9 +2728,12 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l while(totface>0) { totface--; - shadetrapixel(&shpi, (float)x, (float)y, zrow[totface][0], zrow[totface][1], zrow[totface][2], fcol); - sval= addtosampcol(sampcol, fcol, zrow[totface][2]); + shadetrapixel(&shpi, (float)x, (float)y, zrow[totface][0], zrow[totface][1], zrow[totface][2]); + sval= addtosampcol(sampcol, shpi.shr.combined, zrow[totface][2]); + if(addpassflag) + add_transp_passes(rl, od, &shpi.shr); + if(sval==0) break; } @@ -2662,6 +2751,7 @@ void zbuffer_transp_shade(RenderPart *pa, float *pass, unsigned int lay, short l aprect+= pa->rectx; passrect+= 4*pa->rectx; + offs+= pa->rectx; } RE_freeN(APixbuf); diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index 6fbdf9b8641..af34d6ae849 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -1171,7 +1171,7 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int static void sima_draw_zbuffloat_pixels(float x1, float y1, int rectx, int recty, float *rect_float) { - float bias, scale, *rectf; + float bias, scale, *rectf, clipend; int a; if(rect_float==NULL) @@ -1179,7 +1179,8 @@ static void sima_draw_zbuffloat_pixels(float x1, float y1, int rectx, int recty, if(G.scene->camera && G.scene->camera->type==OB_CAMERA) { bias= ((Camera *)G.scene->camera->data)->clipsta; - scale= 1.0f/((Camera *)G.scene->camera->data)->clipend; + clipend= ((Camera *)G.scene->camera->data)->clipend; + scale= 1.0f/(clipend-bias); } else { bias= 0.1f; @@ -1187,9 +1188,16 @@ static void sima_draw_zbuffloat_pixels(float x1, float y1, int rectx, int recty, } rectf= MEM_mallocN(rectx*recty*4, "temp"); - for(a= rectx*recty -1; a>=0; a--) - rectf[a]= (rect_float[a]-bias)*scale; - + for(a= rectx*recty -1; a>=0; a--) { + if(rect_float[a]>clipend) + rectf[a]= 0.0f; + else if(rect_float[a]<bias) + rectf[a]= 1.0f; + else { + rectf[a]= 1.0f - (rect_float[a]-bias)*scale; + rectf[a]*= rectf[a]; + } + } glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_FLOAT, rectf); MEM_freeN(rectf); diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index 9e2dda98728..28001e2918d 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -2031,7 +2031,7 @@ static void view3d_panel_preview(ScrArea *sa, short cntrl) // VIEW3D_HANDLER_PRE if(G.scene->recalc & SCE_PRV_CHANGED) { G.scene->recalc &= ~SCE_PRV_CHANGED; //printf("found recalc\n"); - BIF_view3d_previewrender_free(sa); + BIF_view3d_previewrender_free(sa->spacedata.first); BIF_preview_changed(0); } } diff --git a/source/blender/src/previewrender.c b/source/blender/src/previewrender.c index 75069a05e01..4fbd42bacbe 100644 --- a/source/blender/src/previewrender.c +++ b/source/blender/src/previewrender.c @@ -562,9 +562,8 @@ void BIF_view3d_previewrender_signal(ScrArea *sa, short signal) } } -void BIF_view3d_previewrender_free(ScrArea *sa) +void BIF_view3d_previewrender_free(View3D *v3d) { - View3D *v3d= sa->spacedata.first; if(v3d->ri) { RenderInfo *ri= v3d->ri; @@ -574,8 +573,9 @@ void BIF_view3d_previewrender_free(ScrArea *sa) RE_FreeRender(ri->re); ri->re= NULL; } - ri->status= 0; - ri->cury= 0; + if (v3d->ri->rect) MEM_freeN(v3d->ri->rect); + MEM_freeN(v3d->ri); + v3d->ri= NULL; } } diff --git a/source/blender/src/renderwin.c b/source/blender/src/renderwin.c index 5d98753fdae..49d91aa3a29 100644 --- a/source/blender/src/renderwin.c +++ b/source/blender/src/renderwin.c @@ -127,8 +127,14 @@ typedef struct { Window *win; int rectx, recty; /* size of image */ + + int sparex, sparey; /* spare rect size */ + unsigned int *rectspare; + float *rectsparef; + float zoom, zoomofs[2]; int active; + short storespare, showspare; int mbut[3]; int lmouse[2]; @@ -150,7 +156,7 @@ static RenderWin *render_win= NULL; /* only called in function open_renderwin */ static RenderWin *renderwin_alloc(Window *win) { - RenderWin *rw= MEM_mallocN(sizeof(*rw), "RenderWin"); + RenderWin *rw= MEM_callocN(sizeof(*rw), "RenderWin"); rw->win= win; rw->zoom= 1.0; rw->active= 0; @@ -261,6 +267,7 @@ static void renderwin_draw_render_info(RenderWin *rw) if(RW_HEADERY) { float colf[3]; rcti rect; + char *str; window_get_size(rw->win, &rect.xmax, &rect.ymax); rect.xmin= 0; @@ -274,10 +281,15 @@ static void renderwin_draw_render_info(RenderWin *rw) glClearColor(colf[0], colf[1], colf[2], 1.0); glClear(GL_COLOR_BUFFER_BIT); - if(rw->render_text) { + if(rw->showspare) + str= rw->render_text_spare; + else + str= rw->render_text; + + if(str) { BIF_ThemeColor(TH_TEXT); glRasterPos2i(12, 5); - BMF_DrawString(G.fonts, rw->render_text); + BMF_DrawString(G.fonts, str); } BIF_SetTheme(curarea); // restore theme @@ -318,15 +330,35 @@ static void renderwin_draw(RenderWin *rw, int just_clear) } else { RenderResult rres; - RE_GetResultImage(RE_GetRender("Render"), &rres); + if(rw->showspare) { + rres.rectx= rw->sparex; + rres.recty= rw->sparey; + rres.rect32= rw->rectspare; + rres.rectf= rw->rectsparef; + } + else + RE_GetResultImage(RE_GetRender("Render"), &rres); + if(rres.rectf) { glPixelZoom(rw->zoom, rw->zoom); if(rw->flags & RW_FLAGS_ALPHA) { - /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ - // glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); - // glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rr->rectx, rr->recty, GL_LUMINANCE, GL_UNSIGNED_INT, R.rectot); - // glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); + if(rres.rect32) { + /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ + glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); + glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, GL_LUMINANCE, GL_UNSIGNED_INT, rres.rect32); + glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); + } + else { + float *trectf= MEM_mallocN(rres.rectx*rres.recty*4, "temp"); + int a, b; + + for(a= rres.rectx*rres.recty -1, b= 4*a+3; a>=0; a--, b-=4) + trectf[a]= rres.rectf[b]; + + glaDrawPixelsSafe(fullrect[0][0], fullrect[0][1], rres.rectx, rres.recty, rres.rectx, GL_LUMINANCE, GL_FLOAT, trectf); + MEM_freeN(trectf); + } } else { if(rres.rect32) @@ -499,7 +531,7 @@ static void renderwin_handler(Window *win, void *user_data, short evt, short val renderwin_queue_redraw(render_win); } else if (evt==JKEY) { -// if(R.flag==0) BIF_swap_render_rects(); + if(G.rendering==0) BIF_swap_render_rects(); } else if (evt==ZKEY) { if (rw->flags&RW_FLAGS_OLDZOOM) { @@ -558,8 +590,8 @@ static char *renderwin_get_title(int doswap) swap+= doswap; if(swap & 1) { - if (G.scene->r.renderer==R_YAFRAY) title = "YafRay:Render (spare)"; - else title = "Blender:Render (spare)"; + if (G.scene->r.renderer==R_YAFRAY) title = "YafRay:Render (previous frame)"; + else title = "Blender:Render (previous frame)"; } else { if (G.scene->r.renderer==R_YAFRAY) title = "YafRay:Render"; @@ -1003,6 +1035,39 @@ static void scalefastrect(unsigned int *recto, unsigned int *rectn, int oldx, in } } #endif + +static void renderwin_store_spare(void) +{ + RenderResult rres; + + if(render_win==0 || render_win->storespare==0) + return; + + if(render_win->showspare) { + render_win->showspare= 0; + window_set_title(render_win->win, renderwin_get_title(1)); + } + + if(render_win->render_text_spare) MEM_freeN(render_win->render_text_spare); + render_win->render_text_spare= render_win->render_text; + render_win->render_text= NULL; + + if(render_win->rectspare) MEM_freeN(render_win->rectspare); + render_win->rectspare= NULL; + if(render_win->rectsparef) MEM_freeN(render_win->rectsparef); + render_win->rectsparef= NULL; + + RE_GetResultImage(RE_GetRender("Render"), &rres); + + if(rres.rect32) + render_win->rectspare= MEM_dupallocN(rres.rect32); + else if(rres.rectf) + render_win->rectsparef= MEM_dupallocN(rres.rectf); + + render_win->sparex= rres.rectx; + render_win->sparey= rres.recty; +} + /* -------------- API: externally called --------------- */ /* not used anywhere ??? */ @@ -1016,6 +1081,8 @@ void BIF_renderwin_make_active(void) } #endif + + /* set up display, render an image or scene */ void BIF_do_render(int anim) { @@ -1028,6 +1095,8 @@ void BIF_do_render(int anim) slink_flag = 1; } } + + renderwin_store_spare(); do_render(anim); @@ -1108,41 +1177,27 @@ void BIF_redraw_render_rect(void) void BIF_swap_render_rects(void) { -#if 0 - unsigned int *temp; - - if(R.rectspare==0) { - R.rectspare= (unsigned int *)MEM_callocN(sizeof(int)*R.rectx*R.recty, "rectot"); - R.sparex= R.rectx; - R.sparey= R.recty; - } - else if(R.sparex!=R.rectx || R.sparey!=R.recty) { - temp= (unsigned int *)MEM_callocN(sizeof(int)*R.rectx*R.recty, "rectot"); - - scalefastrect(R.rectspare, temp, R.sparex, R.sparey, R.rectx, R.recty); - MEM_freeN(R.rectspare); - R.rectspare= temp; - - R.sparex= R.rectx; - R.sparey= R.recty; - } + RenderResult rres; - temp= R.rectot; - R.rectot= R.rectspare; - R.rectspare= temp; + if (render_win==NULL) return; - if (render_win) { - char *tmp= render_win->render_text_spare; - render_win->render_text_spare= render_win->render_text; - render_win->render_text= tmp; + render_win->storespare= 1; + render_win->showspare ^= 1; - window_set_title(render_win->win, renderwin_get_title(1)); + RE_GetResultImage(RE_GetRender("Render"), &rres); + if(render_win->sparex!=rres.rectx || render_win->sparey!=rres.recty) { + if(render_win->rectspare) MEM_freeN(render_win->rectspare); + render_win->rectspare= NULL; + if(render_win->rectsparef) MEM_freeN(render_win->rectsparef); + render_win->rectsparef= NULL; } + + window_set_title(render_win->win, renderwin_get_title(1)); /* redraw */ BIF_redraw_render_rect(); -#endif + } /* called from usiblender.c too, to free and close renderwin */ @@ -1152,7 +1207,9 @@ void BIF_close_render_display(void) if (render_win->info_text) MEM_freeN(render_win->info_text); if (render_win->render_text) MEM_freeN(render_win->render_text); if (render_win->render_text_spare) MEM_freeN(render_win->render_text_spare); - + if (render_win->rectspare) MEM_freeN(render_win->rectspare); + if (render_win->rectsparef) MEM_freeN(render_win->rectsparef); + window_destroy(render_win->win); /* ghost close window */ MEM_freeN(render_win); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 1bd37657f65..d005e1473a1 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -219,7 +219,7 @@ void toggle_blockhandler(ScrArea *sa, short eventcode, short val) /* specific free calls */ if(eventcode==VIEW3D_HANDLER_PREVIEW) - BIF_view3d_previewrender_free(sa); + BIF_view3d_previewrender_free(sa->spacedata.first); addnew= 0; } @@ -4714,9 +4714,7 @@ void freespacelist(ScrArea *sa) if(vd->clipbb) MEM_freeN(vd->clipbb); if(G.vd==vd) G.vd= NULL; if(vd->ri) { - BIF_view3d_previewrender_free(sa); - if (vd->ri->rect) MEM_freeN(vd->ri->rect); - MEM_freeN(vd->ri); + BIF_view3d_previewrender_free(vd); } } else if(sl->spacetype==SPACE_OOPS) { @@ -4759,7 +4757,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2) duplicatelist(lb1, lb2); - /* lb1 is copy from lb2, from lb2 we free the file list */ + /* lb1 is copy from lb2, from lb2 we free stuff, rely on event system to properly re-alloc */ sl= lb2->first; while(sl) { @@ -4768,6 +4766,9 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2) sfile->libfiledata= 0; sfile->filelist= 0; } + else if(sl->spacetype==SPACE_VIEW3D) { + BIF_view3d_previewrender_free((View3D *)sl); + } else if(sl->spacetype==SPACE_OOPS) { SpaceOops *so= (SpaceOops *)sl; so->oops.first= so->oops.last= NULL; @@ -4781,15 +4782,6 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2) SpaceNode *snode= (SpaceNode *)sl; snode->nodetree= NULL; } - /* __PINFAKE */ -/* else if(sfile->spacetype==SPACE_ACTION) { - SpaceAction *sa= (SpaceAction *)sfile; - if (sa->flag & SACTION_PIN) - if (sa->action) - sa->action->id.us++; - - } -*/ /* end PINFAKE */ sl= sl->next; } diff --git a/source/blender/src/toets.c b/source/blender/src/toets.c index 9c3957a6fab..b19c5fbbcb2 100644 --- a/source/blender/src/toets.c +++ b/source/blender/src/toets.c @@ -684,7 +684,6 @@ int blenderqread(unsigned short event, short val) break; case JKEY: if(textediting==0 && textspace==0) { - /* NEED CHECK FOR RENDER WINDOW HERE */ if (G.qual==0) { BIF_swap_render_rects(); return 0; |