/* uses ROUNDBOX button in block to get the rect */ static int ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect, rcti *newrect) { Render *re; RenderResult rres; char name[32]; int offx = 0; int newx = BLI_rcti_size_x(rect); int newy = BLI_rcti_size_y(rect); int ok = 0; if (!split || first) sprintf(name, "Preview %p", (void *)sa); else sprintf(name, "SecondPreview %p", (void *)sa); if (split) { if (first) { offx = 0; newx = newx / 2; } else { offx = newx / 2; newx = newx - newx / 2; } } /* test if something rendered ok */ re = RE_GetRender(name); RE_AcquireResultImage(re, &rres); if (rres.rectf) { if (ABS(rres.rectx - newx) < 2 && ABS(rres.recty - newy) < 2) { newrect->xmax = max_ii(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax = max_ii(newrect->ymax, rect->ymin + rres.recty); if (rres.rectx && rres.recty) { unsigned char *rect_byte = MEM_mallocN(rres.rectx * rres.recty * sizeof(int), "ed_preview_draw_rect"); float fx = rect->xmin + offx; float fy = rect->ymin; RE_ResultGet32(re, (unsigned int *)rect_byte); glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte); MEM_freeN(rect_byte); ok = 1; } } } RE_ReleaseResultImage(re); return ok; }
static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int first) { Render *re; Scene *sce; float oldlens; short idtype= GS(id->name); char name[32]; int sizex; /* get the stuff from the builtin preview dbase */ sce= preview_prepare_scene(sp->scene, id, idtype, sp); // XXX sizex if(sce==NULL) return; if(!split || first) sprintf(name, "Preview %p", sp->owner); else sprintf(name, "SecondPreview %p", sp->owner); re= RE_GetRender(name); /* full refreshed render from first tile */ if(re==NULL) re= RE_NewRender(name); /* sce->r gets copied in RE_InitState! */ sce->r.scemode &= ~(R_MATNODE_PREVIEW|R_TEXNODE_PREVIEW); sce->r.scemode &= ~R_NO_IMAGE_LOAD; if(sp->pr_method==PR_ICON_RENDER) { sce->r.scemode |= R_NO_IMAGE_LOAD; sce->r.mode |= R_OSA; } else if(sp->pr_method==PR_NODE_RENDER) { if(idtype == ID_MA) sce->r.scemode |= R_MATNODE_PREVIEW; else if(idtype == ID_TE) sce->r.scemode |= R_TEXNODE_PREVIEW; sce->r.mode &= ~R_OSA; } else { /* PR_BUTS_RENDER */ sce->r.mode |= R_OSA; } /* in case of split preview, use border render */ if(split) { if(first) sizex= sp->sizex/2; else sizex= sp->sizex - sp->sizex/2; } else sizex= sp->sizex; /* allocates or re-uses render result */ sce->r.xsch= sizex; sce->r.ysch= sp->sizey; sce->r.size= 100; /* callbacs are cleared on GetRender() */ if(ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) { RE_display_draw_cb(re, sp, shader_preview_draw); } /* set this for all previews, default is react to G.afbreek still */ RE_test_break_cb(re, sp, shader_preview_break); /* lens adjust */ oldlens= ((Camera *)sce->camera->data)->lens; if(sizex > sp->sizey) ((Camera *)sce->camera->data)->lens *= (float)sp->sizey/(float)sizex; /* entire cycle for render engine */ RE_PreviewRender(re, pr_main, sce); ((Camera *)sce->camera->data)->lens= oldlens; /* handle results */ if(sp->pr_method==PR_ICON_RENDER) { // char *rct= (char *)(sp->pr_rect + 32*16 + 16); if(sp->pr_rect) RE_ResultGet32(re, sp->pr_rect); } else { /* validate owner */ //if(ri->rect==NULL) // ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "BIF_previewrender"); //RE_ResultGet32(re, ri->rect); } /* unassign the pointers, reset vars */ preview_prepare_scene(sp->scene, NULL, GS(id->name), sp); /* XXX bad exception, end-exec is not being called in render, because it uses local main */ // if(idtype == ID_TE) { // Tex *tex= (Tex *)id; // if(tex->use_nodes && tex->nodetree) // ntreeEndExecTree(tex->nodetree); // } }
static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int first) { Render *re; Scene *sce; float oldlens; short idtype = GS(id->name); char name[32]; int sizex; Main *pr_main = sp->pr_main; /* in case of split preview, use border render */ if (split) { if (first) { sizex = sp->sizex / 2; } else { sizex = sp->sizex - sp->sizex / 2; } } else { sizex = sp->sizex; } /* we have to set preview variables first */ sce = preview_get_scene(pr_main); if (sce) { sce->r.xsch = sizex; sce->r.ysch = sp->sizey; sce->r.size = 100; } /* get the stuff from the builtin preview dbase */ sce = preview_prepare_scene(sp->bmain, sp->scene, id, idtype, sp); if (sce == NULL) { return; } if (!split || first) { sprintf(name, "Preview %p", sp->owner); } else { sprintf(name, "SecondPreview %p", sp->owner); } re = RE_GetRender(name); /* full refreshed render from first tile */ if (re == NULL) { re = RE_NewRender(name); } /* sce->r gets copied in RE_InitState! */ sce->r.scemode &= ~(R_MATNODE_PREVIEW | R_TEXNODE_PREVIEW); sce->r.scemode &= ~R_NO_IMAGE_LOAD; if (sp->pr_method == PR_ICON_RENDER) { sce->r.scemode |= R_NO_IMAGE_LOAD; sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8; } else if (sp->pr_method == PR_NODE_RENDER) { if (idtype == ID_MA) { sce->r.scemode |= R_MATNODE_PREVIEW; } else if (idtype == ID_TE) { sce->r.scemode |= R_TEXNODE_PREVIEW; } sce->display.render_aa = SCE_DISPLAY_AA_OFF; } else { /* PR_BUTS_RENDER */ sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8; } /* callbacs are cleared on GetRender() */ if (ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) { RE_display_update_cb(re, sp, shader_preview_update); } /* set this for all previews, default is react to G.is_break still */ RE_test_break_cb(re, sp, shader_preview_break); /* lens adjust */ oldlens = ((Camera *)sce->camera->data)->lens; if (sizex > sp->sizey) { ((Camera *)sce->camera->data)->lens *= (float)sp->sizey / (float)sizex; } /* entire cycle for render engine */ if (idtype == ID_TE) { shader_preview_texture(sp, (Tex *)id, sce, re); } else { /* Render preview scene */ RE_PreviewRender(re, pr_main, sce); } ((Camera *)sce->camera->data)->lens = oldlens; /* handle results */ if (sp->pr_method == PR_ICON_RENDER) { // char *rct= (char *)(sp->pr_rect + 32*16 + 16); if (sp->pr_rect) { RE_ResultGet32(re, sp->pr_rect); } } /* unassign the pointers, reset vars */ preview_prepare_scene(sp->bmain, sp->scene, NULL, GS(id->name), sp); /* XXX bad exception, end-exec is not being called in render, because it uses local main */ // if (idtype == ID_TE) { // Tex *tex= (Tex *)id; // if (tex->use_nodes && tex->nodetree) // ntreeEndExecTree(tex->nodetree); // } }