Improved context handling. Previously FRS_initialize() was used for both

initializing Freestyle and specifying contexts, making the API a bit messy.
Now FRS_initialize() is only for initialization, and contexts are specified
by new FRS_set_context() function just before starting rendering.
This commit is contained in:
Tamito Kajiyama 2009-11-10 00:03:31 +00:00
parent b65008dd6f
commit 51efe7de27
8 changed files with 37 additions and 16 deletions

@ -2671,6 +2671,9 @@ static int screen_render_exec(bContext *C, wmOperator *op)
} }
RE_test_break_cb(re, NULL, (int (*)(void *)) blender_test_break); RE_test_break_cb(re, NULL, (int (*)(void *)) blender_test_break);
/* inform Freestyle of the context */
FRS_set_context(C);
if(RNA_boolean_get(op->ptr, "animation")) if(RNA_boolean_get(op->ptr, "animation"))
RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->frame_step); RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->frame_step);
else else
@ -2945,6 +2948,9 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
/* handle UI stuff */ /* handle UI stuff */
WM_cursor_wait(1); WM_cursor_wait(1);
/* inform Freestyle of the context */
FRS_set_context(C);
/* flush multires changes (for sculpt) */ /* flush multires changes (for sculpt) */
multires_force_update(CTX_data_active_object(C)); multires_force_update(CTX_data_active_object(C));

@ -16,7 +16,8 @@ extern "C" {
extern int freestyle_viewport[4]; extern int freestyle_viewport[4];
// Rendering // Rendering
void FRS_initialize(bContext* C); void FRS_initialize();
void FRS_set_context(bContext* C);
void FRS_add_Freestyle( struct Render* re); void FRS_add_Freestyle( struct Render* re);
void FRS_exit(); void FRS_exit();

@ -71,7 +71,7 @@ extern "C" {
Controller::Controller(bContext* C) Controller::Controller()
{ {
const string sep(Config::DIR_SEP.c_str()); const string sep(Config::DIR_SEP.c_str());
@ -108,7 +108,7 @@ Controller::Controller(bContext* C)
_Canvas = new AppCanvas; _Canvas = new AppCanvas;
_inter = new PythonInterpreter(C); _inter = new PythonInterpreter();
_EnableQI = true; _EnableQI = true;
_ComputeRidges = true; _ComputeRidges = true;
_ComputeSteerableViewMap = false; _ComputeSteerableViewMap = false;
@ -175,6 +175,13 @@ void Controller::setView(AppView *iView)
_Canvas->setViewer(_pView); _Canvas->setViewer(_pView);
} }
void Controller::setContext(bContext *C)
{
PythonInterpreter* py_inter = dynamic_cast<PythonInterpreter*>(_inter);
assert(py_inter != 0);
py_inter->setContext(C);
}
int Controller::LoadMesh(Render *re, SceneRenderLayer* srl) int Controller::LoadMesh(Render *re, SceneRenderLayer* srl)
{ {

@ -66,10 +66,11 @@ extern "C" {
class Controller class Controller
{ {
public: public:
Controller(bContext* C) ; Controller() ;
~Controller() ; ~Controller() ;
void setView(AppView *iView); void setView(AppView *iView);
void setContext(bContext *C);
//soc //soc
void init_options(); void init_options();

@ -45,13 +45,13 @@ extern "C" {
// Initialization // Initialization
//======================================================= //=======================================================
void FRS_initialize(bContext* C){ void FRS_initialize() {
if( freestyle_is_initialized ) if( freestyle_is_initialized )
return; return;
pathconfig = new Config::Path; pathconfig = new Config::Path;
controller = new Controller(C); controller = new Controller();
view = new AppView; view = new AppView;
controller->setView(view); controller->setView(view);
@ -60,6 +60,11 @@ extern "C" {
freestyle_is_initialized = 1; freestyle_is_initialized = 1;
} }
void FRS_set_context(bContext* C) {
cout << "FRS_set_context: context 0x" << C << " scene 0x" << CTX_data_scene(C) << endl;
controller->setContext(C);
}
void FRS_exit() { void FRS_exit() {
delete pathconfig; delete pathconfig;
delete controller; delete controller;
@ -205,7 +210,7 @@ extern "C" {
displayed_layer_count(srl) > 0 ) displayed_layer_count(srl) > 0 )
{ {
cout << "\n----------------------------------------------------------" << endl; cout << "\n----------------------------------------------------------" << endl;
cout << "| "<< srl->name << endl; cout << "| " << (re->scene->id.name+2) << "|" << srl->name << endl;
cout << "----------------------------------------------------------" << endl; cout << "----------------------------------------------------------" << endl;
// prepare Freestyle: // prepare Freestyle:

@ -51,9 +51,9 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
{ {
public: public:
PythonInterpreter(bContext* C) { PythonInterpreter() {
_language = "Python"; _language = "Python";
_context = C; _context = 0;
//Py_Initialize(); //Py_Initialize();
} }
@ -61,6 +61,10 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter
//Py_Finalize(); //Py_Finalize();
} }
void setContext(bContext *C) {
_context = C;
}
int interpretFile(const string& filename) { int interpretFile(const string& filename) {
initPath(); initPath();

@ -89,8 +89,6 @@
#include "GPU_draw.h" #include "GPU_draw.h"
#include "FRS_freestyle.h"
// XXX #include "BPY_extern.h" // XXX #include "BPY_extern.h"
#include "WM_api.h" #include "WM_api.h"
@ -270,8 +268,6 @@ void WM_read_file(bContext *C, char *name, ReportList *reports)
writeBlog(); writeBlog();
} }
FRS_initialize(C);
// XXX undo_editmode_clear(); // XXX undo_editmode_clear();
BKE_reset_undo(); BKE_reset_undo();
BKE_write_undo(C, "original"); /* save current state */ BKE_write_undo(C, "original"); /* save current state */
@ -331,8 +327,6 @@ int WM_read_homefile(bContext *C, wmOperator *op)
strcpy(G.sce, scestr); /* restore */ strcpy(G.sce, scestr); /* restore */
wm_init_userdef(); wm_init_userdef();
FRS_initialize(C);
/* When loading factory settings, the reset solid OpenGL lights need to be applied. */ /* When loading factory settings, the reset solid OpenGL lights need to be applied. */
GPU_default_lights(); GPU_default_lights();

@ -548,6 +548,10 @@ int main(int argc, char **argv)
printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n"); printf("Example: setenv BF_TIFF_LIB /usr/lib/libtiff.so\n");
} }
/* initialize Freestyle */
FRS_initialize();
FRS_set_context(C);
/* OK we are ready for it */ /* OK we are ready for it */
for(a=1; a<argc; a++) { for(a=1; a<argc; a++) {
@ -842,7 +846,6 @@ int main(int argc, char **argv)
if (G.background) { if (G.background) {
int retval = BKE_read_file(C, argv[a], NULL, NULL); int retval = BKE_read_file(C, argv[a], NULL, NULL);
FRS_initialize(C);
/*we successfully loaded a blend file, get sure that /*we successfully loaded a blend file, get sure that
pointcache works */ pointcache works */