/* uses ROUNDBOX button in block to get the rect */ static int ed_preview_draw_rect(ScrArea *sa, wmWindow *win, ID *id, int split, int first, rcti *rect, rcti *newrect) { Render *re; RenderResult rres; char name[32]; const char * gamma_correct_profile=0; int offx=0, newx= rect->xmax-rect->xmin, newy= rect->ymax-rect->ymin; if (id && GS(id->name) != ID_TE) { /* exception: don't color manage texture previews - show the raw values */ if (win){ ColorSpace* cs = BCM_get_ui_colorspace(win); gamma_correct_profile = cs->name; } } 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; } } re= RE_GetRender(name); RE_AcquireResultImage(re, &rres); if(rres.rectf) { if(ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2) { newrect->xmax= MAX2(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax= MAX2(newrect->ymax, rect->ymin + rres.recty); glaDrawPixelsSafe_to32(rect->xmin+offx, rect->ymin, rres.rectx, rres.recty, rres.rectx, rres.rectf, gamma_correct_profile); RE_ReleaseResultImage(re); return 1; } } RE_ReleaseResultImage(re); return 0; }
void render_view3d_draw(RenderEngine *engine, const bContext *C) { Render *re = engine->re; RenderResult rres; int keep_data = render_view3d_changed(engine, C); if (engine->flag & RE_ENGINE_DO_UPDATE) render_view3d_do(engine, C, keep_data); if (re == NULL) return; RE_AcquireResultImage(re, &rres); if (rres.rectf) { Scene *scene = CTX_data_scene(C); bool force_fallback = false; bool need_fallback = true; float dither = scene->r.dither_intensity; /* Dithering is not supported on GLSL yet */ force_fallback |= dither != 0.0f; /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); /* Try using GLSL display transform. */ if (force_fallback == false) { if (IMB_colormanagement_setup_glsl_draw(NULL, &scene->display_settings, TRUE)) { glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glaDrawPixelsTex(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_FLOAT, GL_LINEAR, rres.rectf); glDisable(GL_BLEND); IMB_colormanagement_finish_glsl_draw(); need_fallback = false; } } /* If GLSL failed, use old-school CPU-based transform. */ if (need_fallback) { unsigned char *display_buffer = MEM_mallocN(4 * rres.rectx * rres.recty * sizeof(char), "render_view3d_draw"); IMB_colormanagement_buffer_make_display_space(rres.rectf, display_buffer, rres.rectx, rres.recty, 4, dither, NULL, &scene->display_settings); glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glaDrawPixelsAuto(rres.xof, rres.yof, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, display_buffer); glDisable(GL_BLEND); MEM_freeN(display_buffer); } } RE_ReleaseResultImage(re); }
/* uses UI_BTYPE_ROUNDBOX button in block to get the rect */ static bool 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); bool ok = false; 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); /* material preview only needs monoscopy (view 0) */ RE_AcquireResultImage(re, &rres, 0); 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; /* material preview only needs monoscopy (view 0) */ if (re) RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0); 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; }
/* uses ROUNDBOX button in block to get the rect */ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int first, rcti *rect, rcti *newrect) { Render *re; RenderResult rres; char name[32]; int do_gamma_correct=0; int offx=0, newx= rect->xmax-rect->xmin, newy= rect->ymax-rect->ymin; if (id && GS(id->name) != ID_TE) { /* exception: don't color manage texture previews - show the raw values */ if (sce) do_gamma_correct = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT; } 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; } } re= RE_GetRender(name); RE_AcquireResultImage(re, &rres); if(rres.rectf) { if(ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2) { newrect->xmax= MAX2(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax= MAX2(newrect->ymax, rect->ymin + rres.recty); glaDrawPixelsSafe_to32(rect->xmin+offx, rect->ymin, rres.rectx, rres.recty, rres.rectx, rres.rectf, do_gamma_correct); RE_ReleaseResultImage(re); return 1; } } RE_ReleaseResultImage(re); return 0; }
static void screen_opengl_render_write(OGLRender *oglrender) { Scene *scene = oglrender->scene; RenderResult *rr; bool ok; char name[FILE_MAX]; Object *camera = RE_GetCamera(oglrender->re); rr = RE_AcquireResultRead(oglrender->re); BKE_image_path_from_imformat( name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, &scene->r.im_format, (scene->r.scemode & R_EXTENSION) != 0, false, NULL); /* write images as individual images or stereo */ ok = RE_WriteRenderViewsImage(oglrender->reports, rr, scene, camera, false, name); RE_ReleaseResultImage(oglrender->re); if (ok) printf("OpenGL Render written to '%s'\n", name); else printf("OpenGL Render failed to write '%s'\n", name); }
void render_view3d_draw(RenderEngine *engine, const bContext *C) { Render *re = engine->re; RenderResult rres; char name[32]; render_view3d_do(engine, C); if (re == NULL) { sprintf(name, "View3dPreview %p", (void *)CTX_wm_region(C)); re = RE_GetRender(name); if (re == NULL) return; } /* Viewport render preview doesn't support multiview, view hardcoded to 0 */ RE_AcquireResultImage(re, &rres, 0); if (rres.rectf) { RegionView3D *rv3d = CTX_wm_region_view3d(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); bool force_fallback = false; bool need_fallback = true; float dither = scene->r.dither_intensity; float scale_x, scale_y; rcti clip_rect; int xof, yof; if (render_view3d_disprect(scene, ar, v3d, rv3d, &clip_rect)) { scale_x = (float) BLI_rcti_size_x(&clip_rect) / rres.rectx; scale_y = (float) BLI_rcti_size_y(&clip_rect) / rres.recty; xof = clip_rect.xmin; yof = clip_rect.ymin; } else { scale_x = (float) ar->winx / rres.rectx; scale_y = (float) ar->winy / rres.recty; xof = rres.xof; yof = rres.yof; } /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); /* Try using GLSL display transform. */ if (force_fallback == false) { if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) { glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glPixelZoom(scale_x, scale_y); glaDrawPixelsTex(xof, yof, rres.rectx, rres.recty, GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf); glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); IMB_colormanagement_finish_glsl_draw(); need_fallback = false; } } /* If GLSL failed, use old-school CPU-based transform. */ if (need_fallback) { unsigned char *display_buffer = MEM_mallocN(4 * rres.rectx * rres.recty * sizeof(char), "render_view3d_draw"); IMB_colormanagement_buffer_make_display_space(rres.rectf, display_buffer, rres.rectx, rres.recty, 4, dither, &scene->view_settings, &scene->display_settings); glEnable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glPixelZoom(scale_x, scale_y); glaDrawPixelsAuto(xof, yof, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); MEM_freeN(display_buffer); } } RE_ReleaseResultImage(re); }
/* uses ROUNDBOX button in block to get the rect */ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int first, rcti *rect, rcti *newrect) { Render *re; RenderResult rres; char name[32]; int do_gamma_correct = 0, do_predivide = 0; int offx = 0, newx = rect->xmax - rect->xmin, newy = rect->ymax - rect->ymin; if (id && GS(id->name) != ID_TE) { /* exception: don't color manage texture previews - show the raw values */ if (sce) { do_gamma_correct = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT; do_predivide = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE; } } 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; } } re = RE_GetRender(name); RE_AcquireResultImage(re, &rres); if (rres.rectf) { if (ABS(rres.rectx - newx) < 2 && ABS(rres.recty - newy) < 2) { newrect->xmax = MAX2(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax = MAX2(newrect->ymax, rect->ymin + rres.recty); if (rres.rectx && rres.recty) { /* temporary conversion to byte for drawing */ float fx = rect->xmin + offx; float fy = rect->ymin; int profile_from = (do_gamma_correct) ? IB_PROFILE_LINEAR_RGB : IB_PROFILE_SRGB; int dither = 0; unsigned char *rect_byte; rect_byte = MEM_mallocN(rres.rectx * rres.recty * sizeof(int), "ed_preview_draw_rect"); IMB_buffer_byte_from_float(rect_byte, rres.rectf, 4, dither, IB_PROFILE_SRGB, profile_from, do_predivide, rres.rectx, rres.recty, rres.rectx, rres.rectx); glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte); MEM_freeN(rect_byte); } RE_ReleaseResultImage(re); return 1; } } RE_ReleaseResultImage(re); return 0; }