diff --git a/modules/gfx/pymod/export_scene.cc b/modules/gfx/pymod/export_scene.cc index 267c07e01fa76d2ff39f1996b8273b537ac5db8b..d87d76308e6ef66640861dfa4604d27f3e14c6fe 100644 --- a/modules/gfx/pymod/export_scene.cc +++ b/modules/gfx/pymod/export_scene.cc @@ -48,11 +48,6 @@ GfxObjP scene_getitem(Scene* scene, const String& item) return scene->operator[](item); } -void set_offscreen_mode() -{ - Scene::Instance().SetOffscreenMode(); -} - } // anon ns @@ -60,8 +55,6 @@ void export_Scene() { def("Scene",get_scene,return_value_policy<reference_existing_object>()); - def("set_offscreen_mode",set_offscreen_mode); - // will be removed... def("PickAtom", &pick_atom); diff --git a/modules/gfx/src/scene.cc b/modules/gfx/src/scene.cc index e6cd329a4a2fd08b5f8b80f51098893f92db8de1..4ded0a30cf8471276ac00eba7a59a3c6dafad247 100644 --- a/modules/gfx/src/scene.cc +++ b/modules/gfx/src/scene.cc @@ -1268,9 +1268,8 @@ void Scene::Export(const String& fname, unsigned int width, glGetIntegerv(GL_VIEWPORT,old_vp); bool old_flag=offscreen_flag_; if(!main_offscreen_buffer_) { - LOGN_DEBUG("switching to offscreen rendering"); - glGetIntegerv(GL_VIEWPORT,old_vp); try { + LOGN_DEBUG("creating a " << width <<"x" << height << " offscreen rendering buffer"); OffscreenBuffer ob(width,height,OffscreenBufferFormat(),true); if(!ob.IsValid()) { @@ -1280,7 +1279,6 @@ void Scene::Export(const String& fname, unsigned int width, ob.MakeActive(); offscreen_flag_=true; - root_node_->ContextSwitch(); #if 1 #if OST_SHADER_SUPPORT_ENABLED String shader_name = Shader::Instance().GetCurrentName(); @@ -1294,26 +1292,30 @@ void Scene::Export(const String& fname, unsigned int width, LOGN_DEBUG("updating fog settings"); update_fog(); glDrawBuffer(GL_FRONT); - //this->flag_all_dirty(); + #if OST_SHADER_SUPPORT_ENABLED LOGN_DEBUG("activating shader"); Shader::Instance().Activate(shader_name); #endif + root_node_->ContextSwitch(); #endif } catch (std::exception& e) { - LOGN_ERROR("exception during offscreen rendering: " << e.what()); + LOGN_ERROR("exception during offscreen rendering initialization: " << e.what()); throw; - // noop } + } else { + LOGN_DEBUG("using active main offscreen buffer"); } - LOGN_DEBUG("doing rendering"); + LOGN_DEBUG("rendering into offscreen buffer"); this->RenderGL(); // make sure drawing operations are finished + glFlush(); glFinish(); unsigned int width2=width; unsigned int height2=height; - if(!main_offscreen_buffer_) { + if(main_offscreen_buffer_!=NULL) { + // use settings from active main buffer width2=old_vp[2]; height2=old_vp[3]; } @@ -1334,28 +1336,29 @@ void Scene::Export(const String& fname, unsigned int width, LOGN_DEBUG("calling bitmap export"); BitmapExport(fname,ext,width2,height2,img_data.get()); - if(!main_offscreen_buffer_) { LOGN_DEBUG("switching back to main context"); - if(main_offscreen_buffer_) { - main_offscreen_buffer_->MakeActive(); - } else if (win_) { - win_->MakeActive(); - } else { - LOGN_ERROR("erm, no context to fall back to"); + if (!win_) { return; } + win_->MakeActive(); Scene::Instance().SetViewport(old_vp[2],old_vp[3]); offscreen_flag_=old_flag; root_node_->ContextSwitch(); glDrawBuffer(GL_BACK); LOGN_DEBUG("updating fog"); update_fog(); + } else { + // nothing needs to happen here, main offscreen buffer was active, and stays active } } void Scene::Export(const String& fname, bool transparent) { + if(!win_ && !main_offscreen_buffer_) { + LOGN_ERROR("Export without dimensions either requires an interactive session \nor an active offscreen mode (scene.StartOffscreenMode(W,H))"); + return; + } int d_index=fname.rfind('.'); if (d_index==-1) { LOGN_ERROR("no file extension specified"); @@ -1369,6 +1372,12 @@ void Scene::Export(const String& fname, bool transparent) GLint vp[4]; glGetIntegerv(GL_VIEWPORT,vp); + if(main_offscreen_buffer_) { + this->RenderGL(); + glFlush(); + glFinish(); + } + if (transparent) { glPixelTransferf(GL_ALPHA_BIAS, 0.0); } else { @@ -1694,21 +1703,6 @@ bool Scene::InOffscreenMode() const return offscreen_flag_; } -void Scene::SetOffscreenMode() -{ - if(main_offscreen_buffer_) return; - main_offscreen_buffer_ = new OffscreenBuffer(1000,1000,OffscreenBufferFormat(),false); - if(main_offscreen_buffer_->IsValid()) { - LOGN_DEBUG("activating offscreen buffer"); - main_offscreen_buffer_->MakeActive(); - offscreen_flag_=true; - InitGL(); - } else { - LOGN_DEBUG("offscreen buffer is not valid"); - delete main_offscreen_buffer_; - } -} - float Scene::ElapsedTime() const { #ifndef _MSC_VER diff --git a/modules/gfx/src/scene.hh b/modules/gfx/src/scene.hh index e4ea2c5e99b2fffacd1f25b5a74b8cf24d4d334f..6c88204d22f6bed0291ed1b36fb4650c5eed2a27 100644 --- a/modules/gfx/src/scene.hh +++ b/modules/gfx/src/scene.hh @@ -191,13 +191,15 @@ class DLLEXPORT_OST_GFX Scene { /// \name Export //@} /// \brief export scene into a bitmap, rendering into offscreen of given size + /// if a main offscreen buffer is active (\sa StartOffscreenMode), then the + /// dimensions here are ignored void Export(const String& fname, unsigned int w, unsigned int h, bool transparent=true); /// \brief export snapshot of current scene void Export(const String& fname, bool transparent=true); - /// \brief export scene into povray files names fname.pov and fname.inc + /// \brief export scene into povray files named fname.pov and fname.inc void ExportPov(const std::string& fname, const std::string& wdir="."); //@} /// \brief entry point for gui events (internal use) @@ -321,9 +323,6 @@ class DLLEXPORT_OST_GFX Scene { bool InOffscreenMode() const; - /// \brief internal use - void SetOffscreenMode(); - /// \brief switch into test mode (internal use) void SetTestMode(bool t); @@ -331,7 +330,19 @@ class DLLEXPORT_OST_GFX Scene { Viewport GetViewport() const; + /*! + This method has two different tasks. + + During interactive rendering, it facilitates export + into an offscreen buffer with Scene::Export(file,width,height) + by avoiding repeated initializations of the GL state, e.g. + during animation rendering. + + During batch mode, this is the only way to get meaningful + functionality with the gfx module + */ void StartOffscreenMode(unsigned int w, unsigned int h); + /// \brief stops offline rendering in interactive mode void StopOffscreenMode(); // temporary interface @@ -395,9 +406,9 @@ private: GLuint texture_id_; bool auto_autoslab_; - bool offscreen_flag_; - OffscreenBuffer* main_offscreen_buffer_; - uint old_vp_[2]; + bool offscreen_flag_; // a simple indicator whether in offscreen mode or not + OffscreenBuffer* main_offscreen_buffer_; // not null if a main offscreen buffer is present + uint old_vp_[2]; // used by the offline rendering code uint selection_mode_; diff --git a/scripts/init_cl.py b/scripts/init_cl.py index 216a1e20052c318baddffacf6bf012700732176f..5582502d44b37291f69db910be9c72f8cf71f710 100644 --- a/scripts/init_cl.py +++ b/scripts/init_cl.py @@ -31,7 +31,6 @@ if platform.machine()=='x86_64': else: sys.path.insert(0,os.getenv('DNG_ROOT')+'/lib/openstructure') -#from ost import io, mol, seq, conop, geom from ost import * import ost @@ -51,10 +50,6 @@ import os.path HistoryFile=os.path.expanduser('~/.ost_history') InGUIMode=False -try: - gfx.set_offscreen_mode() -except NameError: - pass sys.ps1='ost> ' sys.ps2='..... ' sys.argv=sys.argv[1:]