int RE_engine_render(Render *re, int do_all) { RenderEngineType *type= RE_engines_find(re->r.engine); RenderEngine *engine; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) { if (re->result) render_result_free(re->result); re->result= render_result_new(re, &re->disprect, 0, 0); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result==NULL) return 1; /* set render info */ re->i.cfra= re->scene->r.cfra; BLI_strncpy(re->i.scenename, re->scene->id.name+2, sizeof(re->i.scenename)); re->i.totface=re->i.totvert=re->i.totstrand=re->i.totlamp=re->i.tothalo= 0; /* render */ engine = RE_engine_create(type); engine->re= re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_PREVIEWBUTS) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0) scene_update_for_newframe(re->main, re->scene, re->lay); if (type->update) type->update(engine, re->main, re->scene); if (type->render) type->render(engine, re->scene); render_result_free_list(&engine->fullresult, engine->fullresult.first); RE_engine_free(engine); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.afbreek = 1; return 1; }
void ED_render_internal_init(void) { RenderEngineType *ret = RE_engines_find(RE_engine_id_BLENDER_RENDER); ret->view_update = render_view3d_update; ret->view_draw = render_view3d_draw; }
static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) { unsigned char obcol[4]; bool is_tex, solidtex; Mesh *me = ob->data; /* XXX scene->obedit warning */ /* texture draw is abused for mask selection mode, do this so wire draw * with face selection in weight paint is not lit. */ if ((v3d->drawtype <= OB_WIRE) && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))) { solidtex = false; Gtexdraw.is_lit = 0; } else if (v3d->drawtype == OB_SOLID || ((ob->mode & OB_MODE_EDIT) && v3d->drawtype != OB_TEXTURE)) { /* draw with default lights in solid draw mode and edit mode */ solidtex = true; Gtexdraw.is_lit = -1; } else { /* draw with lights in the scene otherwise */ solidtex = false; if (v3d->flag2 & V3D_SHADELESS_TEX) Gtexdraw.is_lit = 0; else Gtexdraw.is_lit = GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp); } rgba_float_to_uchar(obcol, ob->col); if (solidtex || v3d->drawtype == OB_TEXTURE) is_tex = true; else is_tex = false; Gtexdraw.ob = ob; Gtexdraw.is_tex = is_tex; Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene); Gtexdraw.use_game_mat = (RE_engines_find(scene->r.engine)->flag & RE_GAME) != 0; Gtexdraw.use_backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; memcpy(Gtexdraw.obcol, obcol, sizeof(obcol)); set_draw_settings_cached(1, NULL, NULL, Gtexdraw); glShadeModel(GL_SMOOTH); glCullFace(GL_BACK); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); }
int RE_engine_render(Render *re, int do_all) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; bool persistent_data = (re->r.mode & R_PERSISTENT_DATA) != 0; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* Lock drawing in UI during data phase. */ if (re->draw_lock) { re->draw_lock(re->dlh, 1); } /* update animation here so any render layer animation is applied before * creating the render result */ if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0) { unsigned int lay = re->lay; /* don't update layers excluded on all render layers */ if (type->flag & RE_USE_EXCLUDE_LAYERS) { SceneRenderLayer *srl; unsigned int non_excluded_lay = 0; if (re->r.scemode & R_SINGLE_LAYER) { srl = BLI_findlink(&re->r.layers, re->r.actlay); if (srl) { non_excluded_lay |= ~srl->lay_exclude; /* in this case we must update all because animation for * the scene has not been updated yet, and so may not be * up to date until after BKE_scene_update_for_newframe */ if (render_layer_exclude_animated(re->scene, srl)) non_excluded_lay |= ~0; } } else { for (srl = re->r.layers.first; srl; srl = srl->next) { if (!(srl->layflag & SCE_LAY_DISABLE)) { non_excluded_lay |= ~srl->lay_exclude; if (render_layer_exclude_animated(re->scene, srl)) non_excluded_lay |= ~0; } } } lay &= non_excluded_lay; } BKE_scene_update_for_newframe_ex(re->eval_ctx, re->main, re->scene, lay, true); render_update_anim_renderdata(re, &re->scene->r); } /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) { int savebuffers = RR_USE_MEM; if (re->result) render_result_free(re->result); if ((type->flag & RE_USE_SAVE_BUFFERS) && (re->r.scemode & R_EXR_TILE_FILE)) savebuffers = RR_USE_EXR; re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result == NULL) { /* Clear UI drawing locks. */ if (re->draw_lock) { re->draw_lock(re->dlh, 0); } return 1; } /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name)); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_BUTS_PREVIEW) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; engine->layer_override = re->layer_override; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, false); engine->tile_x = re->partx; engine->tile_y = re->party; if (re->result->do_exr_tile) render_result_exr_file_begin(re); if (type->update) type->update(engine, re->main, re->scene); /* Clear UI drawing locks. */ if (re->draw_lock) { re->draw_lock(re->dlh, 0); } if (type->render) type->render(engine, re->scene); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; render_result_free_list(&engine->fullresult, engine->fullresult.first); BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_WRITE); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } if (re->r.scemode & R_EXR_CACHE_FILE) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_cache_write(re); BLI_rw_mutex_unlock(&re->resultmutex); } RE_parts_free(re); BLI_rw_mutex_unlock(&re->partsmutex); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = true; #ifdef WITH_FREESTYLE if (re->r.mode & R_EDGE_FRS) RE_RenderFreestyleExternal(re); #endif return 1; }
bool RE_bake_engine( Render *re, Object *object, const BakePixel pixel_array[], const size_t num_pixels, const int depth, const ScenePassType pass_type, float result[]) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; bool persistent_data = (re->r.mode & R_PERSISTENT_DATA) != 0; /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name) - 2); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, false); engine->tile_x = re->r.tilex; engine->tile_y = re->r.tiley; /* update is only called so we create the engine.session */ if (type->update) type->update(engine, re->main, re->scene); if (type->bake) type->bake(engine, re->scene, object, pass_type, pixel_array, num_pixels, depth, result); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_WRITE); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } RE_parts_free(re); BLI_rw_mutex_unlock(&re->partsmutex); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = true; return true; }
bool RE_bake_has_engine(Render *re) { RenderEngineType *type = RE_engines_find(re->r.engine); return (type->bake != NULL); }
bool RE_engine_is_external(Render *re) { RenderEngineType *type = RE_engines_find(re->r.engine); return (type && type->render); }
int RE_engine_render(Render *re, int do_all) { RenderEngineType *type = RE_engines_find(re->r.engine); RenderEngine *engine; int persistent_data = re->r.mode & R_PERSISTENT_DATA; /* verify if we can render */ if (!type->render) return 0; if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW)) return 0; if (do_all && !(type->flag & RE_USE_POSTPROCESS)) return 0; if (!do_all && (type->flag & RE_USE_POSTPROCESS)) return 0; /* update animation here so any render layer animation is applied before * creating the render result */ if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0) { unsigned int lay = re->lay; /* don't update layers excluded on all render layers */ if (type->flag & RE_USE_EXCLUDE_LAYERS) { SceneRenderLayer *srl; unsigned int non_excluded_lay = 0; if (re->r.scemode & R_SINGLE_LAYER) { srl = BLI_findlink(&re->r.layers, re->r.actlay); if (srl) non_excluded_lay |= ~srl->lay_exclude; } else { for (srl = re->r.layers.first; srl; srl = srl->next) if (!(srl->layflag & SCE_LAY_DISABLE)) non_excluded_lay |= ~srl->lay_exclude; } lay &= non_excluded_lay; } BKE_scene_update_for_newframe(re->main, re->scene, lay); } /* create render result */ BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); if (re->result == NULL || !(re->r.scemode & R_BUTS_PREVIEW)) { int savebuffers = RR_USE_MEM; if (re->result) render_result_free(re->result); if ((type->flag & RE_USE_SAVE_BUFFERS) && (re->r.scemode & R_EXR_TILE_FILE)) savebuffers = RR_USE_EXR; re->result = render_result_new(re, &re->disprect, 0, savebuffers, RR_ALL_LAYERS); } BLI_rw_mutex_unlock(&re->resultmutex); if (re->result == NULL) return 1; /* set render info */ re->i.cfra = re->scene->r.cfra; BLI_strncpy(re->i.scene_name, re->scene->id.name + 2, sizeof(re->i.scene_name)); re->i.totface = re->i.totvert = re->i.totstrand = re->i.totlamp = re->i.tothalo = 0; /* render */ engine = re->engine; if (!engine) { engine = RE_engine_create(type); re->engine = engine; } engine->flag |= RE_ENGINE_RENDERING; /* TODO: actually link to a parent which shouldn't happen */ engine->re = re; if (re->flag & R_ANIMATION) engine->flag |= RE_ENGINE_ANIMATION; if (re->r.scemode & R_BUTS_PREVIEW) engine->flag |= RE_ENGINE_PREVIEW; engine->camera_override = re->camera_override; engine->resolution_x = re->winx; engine->resolution_y = re->winy; RE_parts_init(re, FALSE); engine->tile_x = re->partx; engine->tile_y = re->party; if (re->result->do_exr_tile) render_result_exr_file_begin(re); if (type->update) type->update(engine, re->main, re->scene); if (type->render) type->render(engine, re->scene); engine->tile_x = 0; engine->tile_y = 0; engine->flag &= ~RE_ENGINE_RENDERING; render_result_free_list(&engine->fullresult, engine->fullresult.first); /* re->engine becomes zero if user changed active render engine during render */ if (!persistent_data || !re->engine) { RE_engine_free(engine); re->engine = NULL; } if (re->result->do_exr_tile) { BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); render_result_exr_file_end(re); BLI_rw_mutex_unlock(&re->resultmutex); } RE_parts_free(re); if (BKE_reports_contain(re->reports, RPT_ERROR)) G.is_break = TRUE; return 1; }
static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) { unsigned char obcol[4]; bool is_tex, solidtex; Mesh *me = ob->data; ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; /* XXX scene->obedit warning */ /* texture draw is abused for mask selection mode, do this so wire draw * with face selection in weight paint is not lit. */ if ((v3d->drawtype <= OB_WIRE) && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))) { solidtex = false; Gtexdraw.is_lit = 0; } else if (v3d->drawtype == OB_SOLID || ((ob->mode & OB_MODE_EDIT) && v3d->drawtype != OB_TEXTURE) || (BKE_scene_use_new_shading_nodes(scene) && (ob->mode & OB_MODE_TEXTURE_PAINT))) { /* draw with default lights in solid draw mode and edit mode */ solidtex = true; Gtexdraw.is_lit = -1; } else { /* draw with lights in the scene otherwise */ solidtex = false; if (v3d->flag2 & V3D_SHADELESS_TEX) Gtexdraw.is_lit = 0; else Gtexdraw.is_lit = GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp); } rgba_float_to_uchar(obcol, ob->col); if (solidtex || v3d->drawtype == OB_TEXTURE) is_tex = true; else is_tex = false; Gtexdraw.ob = ob; Gtexdraw.stencil = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL) ? imapaint->stencil : NULL; Gtexdraw.is_texpaint = (ob->mode == OB_MODE_TEXTURE_PAINT); Gtexdraw.texpaint_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); Gtexdraw.canvas = (Gtexdraw.texpaint_material) ? NULL : imapaint->canvas; Gtexdraw.is_tex = is_tex; /* naughty multitexturing hacks to quickly support stencil + shading + alpha blending * in new texpaint code. The better solution here would be to support GLSL */ if (Gtexdraw.is_texpaint) { glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); /* load the stencil texture here */ if (Gtexdraw.stencil != NULL) { glActiveTexture(GL_TEXTURE2); if (GPU_verify_image(Gtexdraw.stencil, NULL, false, false, false, false)) { float col[4] = {imapaint->stencil_col[0], imapaint->stencil_col[1], imapaint->stencil_col[2], 1.0f}; glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, col); if ((imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) == 0) { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR); } else { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR); } } } glActiveTexture(GL_TEXTURE0); } Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene); Gtexdraw.use_game_mat = (RE_engines_find(scene->r.engine)->flag & RE_GAME) != 0; Gtexdraw.use_backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; memcpy(Gtexdraw.obcol, obcol, sizeof(obcol)); set_draw_settings_cached(1, NULL, NULL, Gtexdraw); glShadeModel(GL_SMOOTH); glCullFace(GL_BACK); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, (me->flag & ME_TWOSIDED) ? GL_TRUE : GL_FALSE); }
static bool check_engine_supports_textures(Scene *scene) { RenderEngineType *type = RE_engines_find(scene->r.engine); return type->flag & RE_USE_TEXTURE_PREVIEW; }
int BKE_scene_use_new_shading_nodes(Scene *scene) { RenderEngineType *type = RE_engines_find(scene->r.engine); return (type && type->flag & RE_USE_SHADING_NODES); }
static bool check_engine_supports_preview(Scene *scene) { RenderEngineType *type = RE_engines_find(scene->r.engine); return (type->flag & RE_USE_PREVIEW) != 0; }