diff options
author | Ton Roosendaal <ton@blender.org> | 2009-06-25 19:41:27 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2009-06-25 19:41:27 +0400 |
commit | 47ca543b32e74b67e5f8eb6265cc08f93018b002 (patch) | |
tree | 4091e83691f48b26743dfe6f054e5c24e7edd0c5 /source | |
parent | d428ba1de8074e8b0ca2b7c0b060c18ebf7d6b0c (diff) |
2.5
Rendering preview icons is back!
Note for Andrea: the render code has been decoupled from
drawing, it needs Scene context to be able to run...
At the moment only the search menu calls the new render
code (which is the ID browse menu default anyway)
Diffstat (limited to 'source')
5 files changed, 69 insertions, 264 deletions
diff --git a/source/blender/editors/include/ED_previewrender.h b/source/blender/editors/include/ED_previewrender.h index c74cb0f9958..10067510e53 100644 --- a/source/blender/editors/include/ED_previewrender.h +++ b/source/blender/editors/include/ED_previewrender.h @@ -29,17 +29,14 @@ struct View3D; struct SpaceButs; struct RenderInfo; +struct Scene; struct Image; -struct ScrArea; -struct uiBlock; struct Render; struct bContext; struct ID; #define PREVIEW_RENDERSIZE 140 -typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha); - /* stores rendered preview - is also used for icons */ typedef struct RenderInfo { int pr_rectx; @@ -74,6 +71,7 @@ void ED_preview_init_dbase(void); void ED_preview_free_dbase(void); void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, int sizex, int sizey); +void ED_preview_iconrender(struct Scene *scene, struct ID *id, int *rect, int sizex, int sizey); void ED_preview_draw(const struct bContext *C, void *idp, rcti *rect); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index df069069a33..6b566012525 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -41,28 +41,30 @@ #include "BLI_blenlib.h" #include "BLI_storage_types.h" +#include "DNA_material_types.h" #include "DNA_screen_types.h" +#include "DNA_scene_types.h" #include "DNA_userdef_types.h" - -#include "BKE_utildefines.h" #include "BKE_image.h" #include "BKE_icons.h" +#include "BKE_utildefines.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" #include "BIF_gl.h" #include "BIF_glutil.h" -#include "UI_interface.h" -#include "UI_interface_icons.h" -// XXX #include "BIF_previewrender.h" -// XXX #include "BIF_screen.h" +#include "ED_datafiles.h" +#include "ED_previewrender.h" +#include "UI_interface.h" +#include "UI_interface_icons.h" #include "UI_resources.h" /* elubie: should be removed once the enum for the ICONS is in BIF_preview_icons.h */ + #include "interface_intern.h" -#include "ED_datafiles.h" + #define ICON_IMAGE_W 600 #define ICON_IMAGE_H 640 @@ -650,7 +652,6 @@ void UI_icons_init(int first_dyn_id) init_internal_icons(); } -#if 0 static void icon_copy_rect(ImBuf *ibuf, unsigned int w, unsigned int h, unsigned int *rect) { struct ImBuf *ima; @@ -771,18 +772,14 @@ static void set_alpha(char* cp, int sizex, int sizey, char alpha) } } } -#endif /* only called when icon has changed */ /* only call with valid pointer from UI_icon_draw */ -static void icon_set_image(ID *id, DrawInfo *di, PreviewImage* prv_img, int miplevel) +static void icon_set_image(Scene *scene, ID *id, PreviewImage* prv_img, int miplevel) { -#if 0 // XXX - preview renders have to be redesigned - possibly low level op (elubie) RenderInfo ri; unsigned int pr_size = 0; - if (!di) return; - if (!prv_img) { printf("No preview image for this ID: %s\n", id->name); return; @@ -798,13 +795,12 @@ static void icon_set_image(ID *id, DrawInfo *di, PreviewImage* prv_img, int mipl ri.curtile= 0; ri.tottile= 0; - ri.rect = NULL; ri.pr_rectx = prv_img->w[miplevel]; ri.pr_recty = prv_img->h[miplevel]; - pr_size = ri.pr_rectx*ri.pr_recty*sizeof(unsigned int); + ri.rect = MEM_callocN(pr_size, "pr icon rect"); - BIF_previewrender(id, &ri, NULL, PR_ICON_RENDER); + ED_preview_iconrender(scene, id, ri.rect, ri.pr_rectx, ri.pr_recty); /* world is rendered with alpha=0, so it wasn't displayed this could be render option for sky to, for later */ @@ -818,15 +814,11 @@ static void icon_set_image(ID *id, DrawInfo *di, PreviewImage* prv_img, int mipl } } - if (ri.rect) { - memcpy(prv_img->rect[miplevel], ri.rect, pr_size); + memcpy(prv_img->rect[miplevel], ri.rect, pr_size); - /* and clean up */ - MEM_freeN(ri.rect); - ri.rect = 0; - } + /* and clean up */ + MEM_freeN(ri.rect); } -#endif } static void icon_draw_rect(float x, float y, int w, int h, float aspect, int rw, int rh, unsigned int *rect) @@ -912,14 +904,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, int mipl PreviewImage* pi = BKE_previewimg_get((ID*)icon->obj); if (pi) { - if (!nocreate && (pi->changed[miplevel] ||!pi->rect[miplevel])) /* changed only ever set by dynamic icons */ - { - // XXX waitcursor(1); - /* create the preview rect if necessary */ - icon_set_image((ID*)icon->obj, icon->drawinfo, pi, miplevel); - pi->changed[miplevel] = 0; - // XXX waitcursor(0); - } + /* no create icon on this level in code */ if (!pi->rect[miplevel]) return; /* something has gone wrong! */ @@ -928,6 +913,22 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, int mipl } } +void ui_id_icon_render(Scene *scene, ID *id) +{ + PreviewImage *pi = BKE_previewimg_get(id); + + if (pi) { + if ((pi->changed[0] ||!pi->rect[0])) /* changed only ever set by dynamic icons */ + { + /* create the preview rect if necessary */ + icon_set_image(scene, id, pi, 0); + pi->changed[0] = 0; + } + } +} + + + static void icon_draw_mipmap(float x, float y, int icon_id, float aspect, int miplevel, int nocreate) { int draw_size = preview_size(miplevel); diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 379c11a6f31..c27eafd501c 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -44,6 +44,8 @@ struct uiStyle; struct uiWidgetColors; struct uiLayout; struct bContextStore; +struct Scene; +struct ID; /* ****************** general defines ************** */ @@ -425,6 +427,9 @@ void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, char *name, int i /* interface_style.c */ void uiStyleInit(void); +/* interface_icons.c */ +void ui_id_icon_render(struct Scene *scene, struct ID *id); + /* resources.c */ void init_userdef_do_versions(void); void ui_theme_init_userdef(void); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index dd87ee15474..37b2a4af84e 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -46,6 +46,7 @@ #include "UI_interface.h" #include "UI_resources.h" +#include "interface_intern.h" void ui_template_fix_linking() { @@ -160,6 +161,8 @@ static void id_search_cb(const struct bContext *C, void *arg_litem, char *str, u case ID_WO: /* fall through */ case ID_LA: /* fall through */ iconid= BKE_icon_getid(id); + /* checks if not exists, or changed */ + ui_id_icon_render(CTX_data_scene(C), id); break; default: break; diff --git a/source/blender/editors/preview/previewrender.c b/source/blender/editors/preview/previewrender.c index 1ce20fcb0af..1efa5108b96 100644 --- a/source/blender/editors/preview/previewrender.c +++ b/source/blender/editors/preview/previewrender.c @@ -114,46 +114,12 @@ typedef struct ShaderPreview { ID *id; int sizex, sizey; + int *pr_rect; int pr_method; } ShaderPreview; -static void set_previewrect(ScrArea *sa, RenderInfo *ri) -{ - ARegion *ar= NULL; // XXX - rctf viewplane; - - BLI_init_rctf(&viewplane, PR_XMIN, PR_XMAX, PR_YMIN, PR_YMAX); - -// ui_graphics_to_window_rct(ar->win, &viewplane, &ri->disprect); - - /* correction for gla draw */ - BLI_translate_rcti(&ri->disprect, -ar->winrct.xmin, -ar->winrct.ymin); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - glaDefine2DArea(&ar->winrct); - - ri->pr_rectx= (ri->disprect.xmax-ri->disprect.xmin); - ri->pr_recty= (ri->disprect.ymax-ri->disprect.ymin); -} - -static void end_previewrect(ARegion *ar) -{ - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - // restore viewport / scissor which was set by glaDefine2DArea - glViewport(ar->winrct.xmin, ar->winrct.ymin, ar->winx, ar->winy); - glScissor(ar->winrct.xmin, ar->winrct.ymin, ar->winx, ar->winy); - -} /* unused now */ void draw_tex_crop(Tex *tex) @@ -438,196 +404,6 @@ static Scene *preview_prepare_scene(Scene *scene, int id_type, ShaderPreview *sp return NULL; } -void previewrender_progress(void *handle, RenderResult *rr, volatile rcti *renrect) -{ - SpaceButs *sbuts= NULL; // XXX - RenderLayer *rl; - RenderInfo *ri= sbuts->ri; - float ofsx, ofsy; - - if(renrect) return; - - rl= rr->layers.first; - - ofsx= ri->disprect.xmin + rr->tilerect.xmin; - ofsy= ri->disprect.ymin + rr->tilerect.ymin; - - glDrawBuffer(GL_FRONT); - glaDrawPixelsSafe_to32(ofsx, ofsy, rr->rectx, rr->recty, rr->rectx, rl->rectf); - bglFlush(); - glDrawBuffer(GL_BACK); -} - - -/* called by interface_icons.c, or by BIF_previewrender_buts or by nodes... */ -void BIF_previewrender(Scene *scene, struct ID *id, struct RenderInfo *ri, struct ScrArea *area, int pr_method) -{ - SpaceButs *sbuts= NULL; // XXX - Render *re; - RenderStats *rstats; - Scene *sce; - int oldx= ri->pr_rectx, oldy= ri->pr_recty; - char name [32]; - - if(ri->tottile && ri->curtile>=ri->tottile) return; - - /* check for return with a new event */ - if(pr_method!=PR_ICON_RENDER && qtest()) { -// if(area) -// addafterqueue(area->win, RENDERPREVIEW, 1); - return; - } - - /* get the stuff from the builtin preview dbase */ -// sce= preview_prepare_scene(scene, ri, GS(id->name), id, pr_method); - if(sce==NULL) return; - - /* set drawing conditions OK */ - if(area) { - sbuts= area->spacedata.first; /* needed for flag */ - - set_previewrect(area, ri); // uses UImat - - /* because preview render size can differs */ - if(ri->rect && (oldx!=ri->pr_rectx || oldy!=ri->pr_recty)) { - MEM_freeN(ri->rect); - ri->rect= NULL; - ri->curtile= 0; - } - } - -// XXX sprintf(name, "ButsPreview %d", area?area->win:0); - re= RE_GetRender(name); - - /* full refreshed render from first tile */ - if(re==NULL || ri->curtile==0) { - - re= RE_NewRender(name); - - /* handle cases */ - if(pr_method==PR_DRAW_RENDER) { -// RE_display_draw_cb(re, previewrender_progress); -// RE_test_break_cb(re, qtest); - sce->r.scemode |= R_NODE_PREVIEW; - if(sbuts->flag & SB_PRV_OSA) - sce->r.mode |= R_OSA; - sce->r.scemode &= ~R_NO_IMAGE_LOAD; - } - else if(pr_method==PR_DO_RENDER) { -// RE_test_break_cb(re, qtest); - sce->r.scemode |= R_NODE_PREVIEW; - sce->r.scemode &= ~R_NO_IMAGE_LOAD; - } - else { /* PR_ICON_RENDER */ - sce->r.scemode &= ~R_NODE_PREVIEW; - sce->r.scemode |= R_NO_IMAGE_LOAD; - } - - /* allocates render result */ - RE_InitState(re, NULL, &sce->r, ri->pr_rectx, ri->pr_recty, NULL); - - /* enforce preview image clear */ - if(GS(id->name)==ID_MA) { - Material *ma= (Material *)id; - ntreeClearPreview(ma->nodetree); - } - } - /* entire cycle for render engine */ - RE_SetCamera(re, sce->camera); - RE_Database_FromScene(re, sce, 1); - RE_TileProcessor(re, ri->curtile, 0); // actual render engine - RE_Database_Free(re); - - /* handle results */ - if(pr_method==PR_ICON_RENDER) { - if(ri->rect==NULL) - ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "BIF_previewrender"); - RE_ResultGet32(re, ri->rect); - } - else { - rstats= RE_GetStats(re); - - if(rstats->partsdone!=ri->curtile) { - if(ri->rect==NULL) - ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "BIF_previewrender"); - RE_ResultGet32(re, ri->rect); - } - - if(rstats->totpart==rstats->partsdone && rstats->partsdone) { - // allqueues - } - else { -// if(pr_method==PR_DRAW_RENDER && qtest()) -// addafterqueue(area->win, RENDERPREVIEW, 1); - } - - ri->curtile= rstats->partsdone; - ri->tottile= rstats->totpart; - } - - /* unassign the pointers, reset vars */ -// preview_prepare_scene(scene, ri, GS(id->name), NULL, 0); - -} - - -/* afterqueue call */ -void BIF_previewrender_buts(Scene *scene, SpaceButs *sbuts) -{ -// ScrArea *sa= NULL; // XXX - ARegion *ar= NULL; // XXX - uiBlock *block; - struct ID* id = 0; -// struct ID* idfrom = 0; - struct ID* idshow = 0; - Object *ob; - - if (!sbuts->ri) return; - - -// block= uiFindOpenPanelBlockName(&sa->uiblocks, "Preview"); - if(block==NULL) return; - - ob= ((scene->basact)? (scene->basact)->object: 0); - - /* we cant trust this global lockpoin.. for example with headerless window */ -// buttons_active_id(&id, &idfrom); - sbuts->lockpoin= id; - - if(sbuts->mainb==CONTEXT_SHADING) { - int tab= TAB_SHADING_MAT; // XXX sbuts->tab[CONTEXT_SHADING]; - - if(tab==TAB_SHADING_MAT) - idshow = sbuts->lockpoin; - else if(tab==TAB_SHADING_TEX) - idshow = sbuts->lockpoin; - else if(tab==TAB_SHADING_LAMP) { - if(ob && ob->type==OB_LAMP) idshow= ob->data; - } - else if(tab==TAB_SHADING_WORLD) - idshow = sbuts->lockpoin; - } - else if(sbuts->mainb==CONTEXT_OBJECT) { - if(ob && ob->type==OB_LAMP) idshow = ob->data; - } - - if (idshow) { - BKE_icon_changed(BKE_icon_getid(idshow)); -// uiPanelPush(block); -// BIF_previewrender(scene, idshow, sbuts->ri, sbuts->area, PR_DRAW_RENDER); -// uiPanelPop(block); - end_previewrect(ar); - } - else { - /* no active block to draw. But we do draw black if possible */ - if(sbuts->ri->rect) { - memset(sbuts->ri->rect, 0, sizeof(int)*sbuts->ri->pr_rectx*sbuts->ri->pr_recty); - sbuts->ri->tottile= 10000; -// addqueue(sa->win, REDRAW, 1); - } - return; - } -} /* new UI convention: draw is in pixel space already. */ /* uses ROUNDBOX button in block to get the rect */ @@ -1006,7 +782,7 @@ static void shader_preview_updatejob(void *spv) } -/* runs inside thread */ +/* runs inside thread for material, in foreground for icons */ static void shader_preview_startjob(void *customdata, short *stop, short *do_update) { ShaderPreview *sp= customdata; @@ -1064,9 +840,8 @@ static void shader_preview_startjob(void *customdata, short *stop, short *do_upd /* handle results */ if(sp->pr_method==PR_ICON_RENDER) { - //if(ri->rect==NULL) - // ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "BIF_previewrender"); - //RE_ResultGet32(re, ri->rect); + if(sp->pr_rect) + RE_ResultGet32(re, sp->pr_rect); } else { /* validate owner */ @@ -1113,6 +888,29 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, int sizex, in WM_jobs_callbacks(steve, shader_preview_startjob, NULL, shader_preview_updatejob); WM_jobs_start(CTX_wm_manager(C), steve); + + /* signal to rerender icon in menus */ + BKE_icon_changed(BKE_icon_getid(id)); } +/* rect should be allocated, sizex/sizy pixels, 32 bits */ +void ED_preview_iconrender(Scene *scene, ID *id, int *rect, int sizex, int sizey) +{ + ShaderPreview *sp= MEM_callocN(sizeof(ShaderPreview), "ShaderPreview"); + short stop=0, do_update=0; + + /* customdata for preview thread */ + sp->scene= scene; + sp->sizex= sizex; + sp->sizey= sizey; + sp->pr_method= PR_ICON_RENDER; + sp->pr_rect= rect; + sp->id = id; + + shader_preview_startjob(sp, &stop, &do_update); + + MEM_freeN(sp); +} + + |