Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/render/render_preview.c')
-rw-r--r--source/blender/editors/render/render_preview.c502
1 files changed, 57 insertions, 445 deletions
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index 1abf5df223c..007ae96ae59 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -74,7 +74,9 @@
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_node.h"
+#include "BKE_object.h"
#include "BKE_texture.h"
+#include "BKE_world.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
@@ -97,15 +99,6 @@
#include "render_intern.h"
-#define PR_XMIN 10
-#define PR_YMIN 5
-#define PR_XMAX 200
-#define PR_YMAX 195
-
-/* XXX */
-static int qtest(void) {return 0;}
-/* XXX */
-
ImBuf* get_brush_icon(Brush *brush)
{
static const int flags = IB_rect|IB_multilayer|IB_metadata;
@@ -158,9 +151,11 @@ typedef struct ShaderPreview {
ID *parent;
MTex *slot;
- /* node materials/texture need full copy during preview render, glsl uses it too */
+ /* datablocks with nodes need full copy during preview render, glsl uses it too */
Material *matcopy;
Tex *texcopy;
+ Lamp *lampcopy;
+ World *worldcopy;
float col[4]; /* active object color */
@@ -170,129 +165,13 @@ typedef struct ShaderPreview {
} ShaderPreview;
-
-
-/* unused now */
-void draw_tex_crop(Tex *tex)
-{
- rcti rct;
- int ret= 0;
-
- if(tex==NULL) return;
-
- if(tex->type==TEX_IMAGE) {
- if(tex->cropxmin==0.0f) ret++;
- if(tex->cropymin==0.0f) ret++;
- if(tex->cropxmax==1.0f) ret++;
- if(tex->cropymax==1.0f) ret++;
- if(ret==4) return;
-
- rct.xmin= PR_XMIN+2+tex->cropxmin*(PR_XMAX-PR_XMIN-4);
- rct.xmax= PR_XMIN+2+tex->cropxmax*(PR_XMAX-PR_XMIN-4);
- rct.ymin= PR_YMIN+2+tex->cropymin*(PR_YMAX-PR_YMIN-4);
- rct.ymax= PR_YMIN+2+tex->cropymax*(PR_YMAX-PR_YMIN-4);
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
- glColor3ub(0, 0, 0);
- glRecti(rct.xmin+1, rct.ymin-1, rct.xmax+1, rct.ymax-1);
-
- glColor3ub(255, 255, 255);
- glRecti(rct.xmin, rct.ymin, rct.xmax, rct.ymax);
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
-
-}
-
-/* temporal abuse; if id_code is -1 it only does texture.... solve! */
-void BIF_preview_changed(short UNUSED(id_code))
-{
-#if 0
- ScrArea *sa;
-
- for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
- if(sa->spacetype==SPACE_BUTS) {
- SpaceButs *sbuts= sa->spacedata.first;
- if(sbuts->mainb==CONTEXT_SHADING) {
- int tab= sbuts->tab[CONTEXT_SHADING];
- if(tab==TAB_SHADING_MAT && (id_code==ID_MA || id_code==ID_TE)) {
- if (sbuts->ri) sbuts->ri->curtile= 0;
- addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
- else if(tab==TAB_SHADING_TEX && (id_code==ID_TE || id_code==-1)) {
- if (sbuts->ri) sbuts->ri->curtile= 0;
- addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
- else if(tab==TAB_SHADING_LAMP && (id_code==ID_LA || id_code==ID_TE)) {
- if (sbuts->ri) sbuts->ri->curtile= 0;
- addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
- else if(tab==TAB_SHADING_WORLD && (id_code==ID_WO || id_code==ID_TE)) {
- if (sbuts->ri) sbuts->ri->curtile= 0;
- addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
- }
- else if (sbuts->ri)
- sbuts->ri->curtile= 0; /* ensure changes always result in re-render when context is restored */
- }
- else if(sa->spacetype==SPACE_NODE) {
- SpaceNode *snode= sa->spacedata.first;
- if(snode->treetype==NTREE_SHADER && (id_code==ID_MA || id_code==ID_TE)) {
- snode_tag_dirty(snode);
- }
- }
- else if(sa->spacetype==SPACE_VIEW3D) {
- View3D *vd= sa->spacedata.first;
- /* if is has a renderinfo, we consider that reason for signalling */
- if (vd->ri) {
- vd->ri->curtile= 0;
- addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
- }
- }
-
- if(ELEM4(id_code, ID_MA, ID_TE, ID_LA, ID_WO)) {
- Object *ob;
- Material *ma;
-
- if(id_code == ID_WO) {
- for(ma=G.main->mat.first; ma; ma=ma->id.next) {
- if(ma->gpumaterial.first) {
- GPU_material_free(ma);
- }
- }
- }
- else if(id_code == ID_LA) {
- for(ob=G.main->object.first; ob; ob=ob->id.next) {
- if(ob->gpulamp.first) {
- GPU_lamp_free(ob);
- }
- }
-
- for(ma=G.main->mat.first; ma; ma=ma->id.next) {
- if(ma->gpumaterial.first) {
- GPU_material_free(ma);
- }
- }
- } else if(OBACT) {
- Object *ob = OBACT;
-
- ma= give_current_material(ob, ob->actcol);
- if(ma && ma->gpumaterial.first) {
- GPU_material_free(ma);
- }
- }
- }
-#endif
-}
-
/* *************************** Preview for buttons *********************** */
static Main *pr_main= NULL;
void ED_preview_init_dbase(void)
{
+#ifndef WITH_HEADLESS
BlendFileData *bfd;
extern int datatoc_preview_blend_size;
extern char datatoc_preview_blend[];
@@ -306,6 +185,7 @@ void ED_preview_init_dbase(void)
MEM_freeN(bfd);
}
G.fileflags= fileflags;
+#endif
}
void ED_preview_free_dbase(void)
@@ -385,7 +265,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
if(id_type==ID_MA) {
Material *mat= NULL, *origmat= (Material *)id;
- if(id) {
+ if(origmat) {
/* work on a copy */
mat= localize_material(origmat);
sp->matcopy= mat;
@@ -515,7 +395,14 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
}
}
else if(id_type==ID_LA) {
- Lamp *la= (Lamp *)id;
+ Lamp *la= NULL, *origla= (Lamp *)id;
+
+ /* work on a copy */
+ if(origla) {
+ la= localize_lamp(origla);
+ sp->lampcopy= la;
+ BLI_addtail(&pr_main->lamp, la);
+ }
if(la && la->type==LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) {
sce->lay= 1<<MA_ATMOS;
@@ -537,8 +424,16 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
}
}
else if(id_type==ID_WO) {
+ World *wrld= NULL, *origwrld= (World *)id;
+
+ if(origwrld) {
+ wrld= localize_world(origwrld);
+ sp->worldcopy= wrld;
+ BLI_addtail(&pr_main->world, wrld);
+ }
+
sce->lay= 1<<MA_SKY;
- sce->world= (World *)id;
+ sce->world= wrld;
}
return sce;
@@ -636,321 +531,6 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r
}
}
-/* ******************************** Icon Preview **************************** */
-
-void ED_preview_icon_draw(const bContext *UNUSED(C), void *UNUSED(idp), void *UNUSED(arg1), void *UNUSED(arg2), rcti *UNUSED(rect))
-{
-}
-
-/* *************************** Preview for 3d window *********************** */
-
-void view3d_previewrender_progress(RenderResult *rr, volatile rcti *renrect)
-{
-// ScrArea *sa= NULL; // XXX
-// View3D *v3d= NULL; // XXX
- RenderLayer *rl;
- int ofsx=0, ofsy=0;
-
- if(renrect) return;
-
- rl= rr->layers.first;
-
- /* this case is when we render envmaps... */
-// if(rr->rectx > v3d->ri->pr_rectx || rr->recty > v3d->ri->pr_recty)
-// return;
-
-// ofsx= v3d->ri->disprect.xmin + rr->tilerect.xmin;
-// ofsy= v3d->ri->disprect.ymin + rr->tilerect.ymin;
-
- glDrawBuffer(GL_FRONT);
-// glaDefine2DArea(&sa->winrct);
- glaDrawPixelsSafe_to32(ofsx, ofsy, rr->rectx, rr->recty, rr->rectx, rl->rectf, 0);
- bglFlush();
- glDrawBuffer(GL_BACK);
-
-}
-
-void BIF_view3d_previewrender_signal(ScrArea *UNUSED(sa), short UNUSED(signal))
-{
-#if 0
- View3D *v3d= sa->spacedata.first;
-
- /* this can be called from other window... solve! */
- if(sa->spacetype!=SPACE_VIEW3D)
- return; // XXX
-
- if(v3d && v3d->ri) {
- RenderInfo *ri= v3d->ri;
- ri->status &= ~signal;
- ri->curtile= 0;
- //printf("preview signal %d\n", signal);
- if(ri->re && (signal & PR_DBASE))
- RE_Database_Free(ri->re);
-
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
-#endif
-}
-
-void BIF_view3d_previewrender_free(View3D *UNUSED(v3d))
-{
-#if 0
- if(v3d->ri) {
- RenderInfo *ri= v3d->ri;
- if(ri->re) {
-// printf("free render\n");
- RE_Database_Free(ri->re);
- RE_FreeRender(ri->re);
- ri->re= NULL;
- }
- if (v3d->ri->rect) MEM_freeN(v3d->ri->rect);
- MEM_freeN(v3d->ri);
- v3d->ri= NULL;
- }
-#endif
-}
-
-/* returns 1 if OK, do not call while in panel space! */
-static int view3d_previewrender_get_rects(ScrArea *sa, rctf *viewplane, RenderInfo *ri, float *clipsta, float *clipend, int *ortho, float *pixsize)
-{
- View3D *v3d= NULL; // XXX
- RegionView3D *rv3d= NULL; // XXX
- int rectx, recty;
-// uiBlock *block;
-
-// block= uiFindOpenPanelBlockName(&sa->uiblocks, "Preview");
-// if(block==NULL) return 0;
-
- /* calculate preview rect size */
-// BLI_init_rctf(viewplane, 15.0f, (block->maxx - block->minx)-15.0f, 15.0f, (block->maxy - block->miny)-15.0f);
-// uiPanelPush(block);
-// ui_graphics_to_window_rct(sa->win, viewplane, &ri->disprect);
-// uiPanelPop(block);
-
- /* correction for gla draw */
-// BLI_translate_rcti(&ri->disprect, -sa->winrct.xmin, -sa->winrct.ymin);
-
- *ortho= get_view3d_viewplane(v3d, rv3d, sa->winx, sa->winy, viewplane, clipsta, clipend, pixsize);
-
- rectx= ri->disprect.xmax - ri->disprect.xmin;
- recty= ri->disprect.ymax - ri->disprect.ymin;
-
- if(rectx<4 || recty<4) return 0;
-
- if(ri->rect && (rectx!=ri->pr_rectx || recty!=ri->pr_recty)) {
- MEM_freeN(ri->rect);
- ri->rect= NULL;
- ri->curtile= 0;
- printf("changed size\n");
- }
- ri->pr_rectx= rectx;
- ri->pr_recty= recty;
-
- return 1;
-}
-
-/* called before a panel gets moved/scaled, makes sure we can see through */
-void BIF_view3d_previewrender_clear(ScrArea *UNUSED(sa))
-{
-#if 0
- View3D *v3d= sa->spacedata.first;
-
- if(v3d->ri) {
- RenderInfo *ri= v3d->ri;
- ri->curtile= 0;
- if(ri->rect)
- MEM_freeN(ri->rect);
- ri->rect= NULL;
- }
-#endif
-}
-
-/* afterqueue call */
-void BIF_view3d_previewrender(Main *bmain, Scene *scene, ScrArea *sa)
-{
- View3D *v3d= sa->spacedata.first;
- RegionView3D *rv3d= NULL; // XXX
- Render *re;
- RenderInfo *ri=NULL; /* preview struct! */
- RenderStats *rstats;
- RenderData rdata;
- rctf viewplane;
- float clipsta, clipend, pixsize;
- int orth;
-
- /* first get the render info right */
-// if (!v3d->ri) {
-// ri= v3d->ri= MEM_callocN(sizeof(RenderInfo), "butsrenderinfo");
-// ri->tottile= 10000;
-// }
-// ri= v3d->ri;
-
- if(0==view3d_previewrender_get_rects(sa, &viewplane, ri, &clipsta, &clipend, &orth, &pixsize))
- return;
-
- /* render is finished, so return */
- if(ri->tottile && ri->curtile>=ri->tottile) return;
-
- /* or return with a new event */
- if(qtest()) {
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
- return;
- }
- //printf("Enter previewrender\n");
- /* ok, are we rendering all over? */
- if(ri->re==NULL) {
- char name[32];
-
- ri->status= 0;
-
- sprintf(name, "View3dPreview %p", (void *)sa);
- re= ri->re= RE_NewRender(name);
- //RE_display_draw_cb(re, view3d_previewrender_progress);
- //RE_stats_draw_cb(re, view3d_previewrender_stats);
- //RE_test_break_cb(re, qtest);
-
- /* no osa, blur, seq, layers, etc for preview render */
- rdata= scene->r;
- rdata.mode &= ~(R_OSA|R_MBLUR);
- rdata.scemode &= ~(R_DOSEQ|R_DOCOMP|R_FREE_IMAGE);
- rdata.layers.first= rdata.layers.last= NULL;
- rdata.renderer= R_INTERN;
-
- RE_InitState(re, NULL, &rdata, NULL, sa->winx, sa->winy, &ri->disprect);
-
- if(orth)
- RE_SetOrtho(re, &viewplane, clipsta, clipend);
- else
- RE_SetWindow(re, &viewplane, clipsta, clipend);
- RE_SetPixelSize(re, pixsize);
-
- /* until here are no escapes */
- ri->status |= PR_DISPRECT;
- ri->curtile= 0;
- //printf("new render\n");
- }
-
- re= ri->re;
-
- PIL_sleep_ms(100); /* wait 0.1 second if theres really no event... */
- if(qtest()==0) {
-
- /* check status */
- if((ri->status & PR_DISPRECT)==0) {
- RE_SetDispRect(ri->re, &ri->disprect);
- if(orth)
- RE_SetOrtho(ri->re, &viewplane, clipsta, clipend);
- else
- RE_SetWindow(ri->re, &viewplane, clipsta, clipend);
- RE_SetPixelSize(re, pixsize);
- ri->status |= PR_DISPRECT;
- ri->curtile= 0;
- //printf("disprect update\n");
- }
- if((ri->status & PR_DBASE)==0) {
- unsigned int lay= scene->lay;
-
- RE_SetView(re, rv3d->viewmat);
-
- /* allow localview render for objects with lights in normal layers */
- if(v3d->lay & 0xFF000000)
- lay |= v3d->lay;
- else lay= v3d->lay;
-
- RE_Database_FromScene(re, bmain, scene, lay, 0); // 0= dont use camera view
-
- rstats= RE_GetStats(re);
- if(rstats->convertdone)
- ri->status |= PR_DBASE|PR_PROJECTED|PR_ROTATED;
- ri->curtile= 0;
-
- /* database can have created render-resol data... */
- if(rstats->convertdone)
- DAG_scene_flush_update(bmain, scene, scene->lay, 0);
-
- //printf("dbase update\n");
- }
- if((ri->status & PR_PROJECTED)==0) {
- if(ri->status & PR_DBASE) {
- if(orth)
- RE_SetOrtho(ri->re, &viewplane, clipsta, clipend);
- else
- RE_SetWindow(ri->re, &viewplane, clipsta, clipend);
- RE_DataBase_ApplyWindow(re);
- ri->status |= PR_PROJECTED;
- }
- ri->curtile= 0;
- //printf("project update\n");
- }
-
- /* OK, can we enter render code? */
- if(ri->status==(PR_DISPRECT|PR_DBASE|PR_PROJECTED|PR_ROTATED)) {
- //printf("curtile %d tottile %d\n", ri->curtile, ri->tottile);
- RE_TileProcessor(ri->re); //, ri->curtile, 0);
-
- if(ri->rect==NULL)
- ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "preview view3d rect");
-
- RE_ResultGet32(ri->re, ri->rect);
- }
-
- rstats= RE_GetStats(ri->re);
-// if(rstats->totpart==rstats->partsdone && rstats->partsdone)
-// addqueue(sa->win, REDRAW, 1);
-// else
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
-
- ri->curtile= rstats->partsdone;
- ri->tottile= rstats->totpart;
- }
- else {
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
- }
-
- //printf("\n");
-}
-
-/* in panel space! */
-static void view3d_previewdraw_rect(ScrArea *UNUSED(sa), uiBlock *UNUSED(block), RenderInfo *ri)
-{
-// rctf dispf;
-
- if(ri->rect==NULL)
- return;
-
-// BLI_init_rctf(&dispf, 15.0f, (block->maxx - block->minx)-15.0f, 15.0f, (block->maxy - block->miny)-15.0f);
-// ui_graphics_to_window_rct(sa->win, &dispf, &ri->disprect);
-
- /* correction for gla draw */
-// BLI_translate_rcti(&ri->disprect, -sa->winrct.xmin, -sa->winrct.ymin);
-
- /* when panel scale changed, free rect */
- if(ri->disprect.xmax-ri->disprect.xmin != ri->pr_rectx ||
- ri->disprect.ymax-ri->disprect.ymin != ri->pr_recty) {
- MEM_freeN(ri->rect);
- ri->rect= NULL;
- }
- else {
-// glaDefine2DArea(&sa->winrct);
- glaDrawPixelsSafe(ri->disprect.xmin, ri->disprect.ymin, ri->pr_rectx, ri->pr_recty, ri->pr_rectx, GL_RGBA, GL_UNSIGNED_BYTE, ri->rect);
- }
-}
-
-/* is panel callback, supposed to be called with correct panel offset matrix */
-void BIF_view3d_previewdraw(struct ScrArea *sa, struct uiBlock *block)
-{
- RegionView3D *rv3d= NULL;
-
-// if (v3d->ri==NULL || v3d->ri->rect==NULL)
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
-// else {
- view3d_previewdraw_rect(sa, block, rv3d->ri);
-// if(v3d->ri->curtile==0)
-// addafterqueue(sa->win, RENDERPREVIEW, 1);
-// }
-}
-
-
/* **************************** new shader preview system ****************** */
/* inside thread, called by renderer, sets job update value */
@@ -1148,6 +728,38 @@ static void shader_preview_free(void *customdata)
}
MEM_freeN(sp->texcopy);
}
+ if(sp->worldcopy) {
+ struct IDProperty *properties;
+ /* node previews */
+ shader_preview_updatejob(sp);
+
+ /* get rid of copied world */
+ BLI_remlink(&pr_main->world, sp->worldcopy);
+ free_world(sp->worldcopy);
+
+ properties= IDP_GetProperties((ID *)sp->worldcopy, FALSE);
+ if (properties) {
+ IDP_FreeProperty(properties);
+ MEM_freeN(properties);
+ }
+ MEM_freeN(sp->worldcopy);
+ }
+ if(sp->lampcopy) {
+ struct IDProperty *properties;
+ /* node previews */
+ shader_preview_updatejob(sp);
+
+ /* get rid of copied lamp */
+ BLI_remlink(&pr_main->lamp, sp->lampcopy);
+ free_lamp(sp->lampcopy);
+
+ properties= IDP_GetProperties((ID *)sp->lampcopy, FALSE);
+ if (properties) {
+ IDP_FreeProperty(properties);
+ MEM_freeN(properties);
+ }
+ MEM_freeN(sp->lampcopy);
+ }
MEM_freeN(sp);
}