BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
renderSetup.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_VIEW_RENDERING_RENDERSETUP_H
6 #define BALL_VIEW_RENDERING_RENDERSETUP_H
7 
8 #ifndef BALL_VIEW_RENDERING_GLRENDERER_H
10 #endif
11 
12 #ifndef BALL_VIEW_RENDERING_RENDERTARGET_H
14 #endif
15 
16 #ifndef BALL_VIEW_RENDERING_GLRENDERWINDOW_H
18 #endif
19 
20 #ifndef BALL_SYSTEM_MUTEX_H
21 # include <BALL/SYSTEM/mutex.h>
22 #endif
23 
24 #include <QtCore/QThread>
25 #include <QtCore/QWaitCondition>
26 
27 #include <boost/enable_shared_from_this.hpp>
28 
29 #include <deque>
30 
31 class QImage;
32 
33 namespace BALL {
34  namespace VIEW {
35 
36  class ColorMap;
37  class Scene;
38 
45  : public QThread, public boost::enable_shared_from_this<RenderSetup>
46  {
47  public:
48  RenderSetup(Renderer* r, RenderTarget* t, Scene* scene, const Stage* stage);
49 
50  RenderSetup(const RenderSetup& rs);
51 
52  virtual ~RenderSetup();
53 
54  const RenderSetup& operator = (const RenderSetup& rs);
55 
56  // TODO: this should be boost smart pointers!
59 
63  {
65  UNKNOWN_RENDERER = 0,
66 
69 
72 
75 
78 
81 
83  RTFACT_RENDERER
84  };
85 
86  enum STEREO_SETUP {
89  RIGHT_EYE
90  };
91 
94  void init();
95 
98  void resize(Size width, Size height);
99 
106  void pauseRendering() { rendering_paused_ = true; }
107 
113  void startRendering() { rendering_paused_ = false; }
114 
117  bool isPaused() const { return rendering_paused_; }
118 
121  RendererType getRendererType() { return renderer_type_; }
122 
138  void setReceiveBufferUpdates(bool do_receive) { receive_updates_ = do_receive; }
139 
142  bool receivesBufferUpdates() const { return receive_updates_; };
143 
149  void updateCamera(const Camera* camera = 0);
150 
156  void setOffset(const Vector3& offset);
157 
164  void setStereoMode(STEREO_SETUP stereo) { stereo_setup_ = stereo; };
165 
170  void bufferRepresentation(const Representation& rep);
171 
176  void removeRepresentation(const Representation& rep);
177 
184  void renderToBuffer();
185 
188  bool exportPNG(const String& filename);
189 
192  void setLights(bool reset_all = false);
193 
196  void updateBackgroundColor();
197 
200  void setupEnvironmentMap(const QImage& image);
201 
207  Position prepareGridTextures(const RegularData3D& grid, const ColorMap& map);
208 
214  void removeGridTextures(const RegularData3D& grid);
215 
219  Vector3 mapViewportTo3D(Position x, Position y);
220 
224  Vector2 map3DToViewport(const Vector3& vec);
225 
228  void pickObjects(Position x1, Position y1, Position x2, Position y2, std::list<GeometricObject*>& objects);
229 
238  void showRuler(bool show);
239 
240  void updateMaterialForRepresentation(const Representation* rep);
241 
244  void projectionModeChanged();
245 
248  void useContinuousLoop(bool use_loop);
249 
254  void stop() { MutexLocker ml(&render_mutex_); about_to_quit_ = true; }
255 
258  bool isAboutToQuit() { return about_to_quit_; }
259 
262  bool isContinuous() { return use_continuous_loop_; }
263 
272  void setTimeToLive(int ttl) { ttl_ = ttl; }
273 
276  int getTimeToLive() const { return ttl_; }
277 
280  void exportPNGAfterTTL(String filename) { export_after_ttl_ = true; export_after_ttl_filename_ = filename; }
281 
288  virtual void makeCurrent();
289 
290  virtual void run();
291 
292  void lock() { render_mutex_.lock(); }
293  void unlock() { render_mutex_.unlock(); }
294 
295  mutable QWaitCondition wait_for_render;
296  // locks the renderer before the next render call
297  mutable Mutex loop_mutex;
298 
300  bool bufferIsReady() { return buffer_is_ready_; }
301 
303  bool isReadyToSwap();
304 
306  void setBufferReady(bool is_ready) { buffer_is_ready_ = is_ready; }
307 
309  std::deque<boost::shared_ptr<RenderSetup> >& getDependentRenderers() { return keep_in_sync_; }
310 
312  void makeDependentOn(boost::shared_ptr<RenderSetup>& partner) { keep_in_sync_.push_back(partner); }
313 
314  protected:
315  // does the hard work and can be called from a continuous loop as well as from event-based rendering
316  void renderToBuffer_();
317 
318  void initType_();
319 
323 
325 
328 
330 
331  // switches between rendering continously and rendering upon events
333 
335  Stage const* stage_;
336 
337  // locks the renderer during updates and rendering
339 
341 
342  // This pointer is used to avoid uneccessary RTTI calls and casting. If the target is not a
343  // GLRenderWindow or one of its derived classes, this pointer will simply be NULL
345 
346  // This pointer is used to avoid uneccessary RTTI calls and casting. If the renderer is not a
347  // GLRenderer or one of its derived classes, this pointer will simply be NULL
349 
350  // The number of render operations to perform before destruction
351  int ttl_;
352 
355 
356  // a list of render setups that should be synchronized with this one so that buffer
357  // swaps only happen simulatneously
358  std::deque<boost::shared_ptr<RenderSetup> > keep_in_sync_;
359 
361 
362  // the type of the encapsulated renderer
364  };
365 
369  : public QEvent
370  {
371  public:
372  RenderToBufferFinishedEvent(boost::shared_ptr<RenderSetup> renderer)
373  : QEvent(static_cast<QEvent::Type>(RENDER_TO_BUFFER_FINISHED_EVENT)),
374  renderer_(renderer)
375  {};
376 
377  boost::shared_ptr<RenderSetup> getRenderer() { return renderer_; }
378 
379  protected:
380  boost::shared_ptr<RenderSetup> renderer_;
381  };
382 
383  }
384 }
385 
386 #endif
Renders into a POVRay file.
Definition: renderSetup.h:71
RenderToBufferFinishedEvent(boost::shared_ptr< RenderSetup > renderer)
Definition: renderSetup.h:372
void exportPNGAfterTTL(String filename)
Definition: renderSetup.h:280
GLRenderWindow * gl_target_
Definition: renderSetup.h:344
void setReceiveBufferUpdates(bool do_receive)
Definition: renderSetup.h:138
bool isPaused() const
Definition: renderSetup.h:117
Stage const * stage_
Definition: renderSetup.h:335
RenderTarget * target
Definition: renderSetup.h:58
Standard OpenGL renderer.
Definition: renderSetup.h:68
std::deque< boost::shared_ptr< RenderSetup > > keep_in_sync_
Definition: renderSetup.h:358
void setBufferReady(bool is_ready)
Definition: renderSetup.h:306
STEREO_SETUP stereo_setup_
Definition: renderSetup.h:329
boost::shared_ptr< RenderSetup > renderer_
Definition: renderSetup.h:380
RendererType getRendererType()
Definition: renderSetup.h:121
GLRenderer * gl_renderer_
Definition: renderSetup.h:348
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
bool bufferIsReady()
Returns true if the buffer has been filled and just waits for painting.
Definition: renderSetup.h:300
RendererType renderer_type_
Definition: renderSetup.h:363
QWaitCondition wait_for_render
Definition: renderSetup.h:295
Renders into a VRML file.
Definition: renderSetup.h:74
Event posted by renderers after a new buffer is available.
boost::shared_ptr< RenderSetup > getRenderer()
Definition: renderSetup.h:377
std::deque< boost::shared_ptr< RenderSetup > > & getDependentRenderers()
Definition: renderSetup.h:309
Used for offscreen rendering.
Definition: renderSetup.h:80
void setTimeToLive(int ttl)
Definition: renderSetup.h:272
void makeDependentOn(boost::shared_ptr< RenderSetup > &partner)
Definition: renderSetup.h:312
Renders into an STL file.
Definition: renderSetup.h:77
int getTimeToLive() const
Definition: renderSetup.h:276
bool receivesBufferUpdates() const
Definition: renderSetup.h:142
void setStereoMode(STEREO_SETUP stereo)
Definition: renderSetup.h:164