Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderqueue.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_RENDER_RENDERQUEUE_H_)
21 #define __MITSUBA_RENDER_RENDERQUEUE_H_
22 
23 #include <mitsuba/mitsuba.h>
24 #include <mitsuba/render/rectwu.h>
25 
27 
28 /**
29  * \brief Abstract render listener - can be used to react to
30  * progress messages (e.g. in a GUI)
31  * \ingroup librender
32  */
34 public:
35  /// Called when work has begun in a rectangular image region
36  virtual void workBeginEvent(const RenderJob *job, const RectangularWorkUnit *wu, int worker);
37 
38  /// Called when work has finished in a rectangular image region
39  virtual void workEndEvent(const RenderJob *job, const ImageBlock *wr, bool cancelled);
40 
41  /// Called when work has been canceled in a rectangular image region
42  virtual void workCanceledEvent(const RenderJob *job, const Point2i &offset,
43  const Vector2i &size);
44 
45  /// Called when the whole target image has been altered in some way.
46  virtual void refreshEvent(const RenderJob *job);
47 
48  /// Called when a render job has completed successfully or unsuccessfully
49  virtual void finishJobEvent(const RenderJob *job, bool cancelled);
50 
52 protected:
53  virtual ~RenderListener() { }
54 };
55 
56 /**
57  * \brief Render queue - used to keep track of a number of scenes
58  * that are simultaneously being rendered.
59  *
60  * This class is also responsible for distributing events about
61  * in-progress renderings to registered listeners.
62  *
63  * \ingroup librender
64  */
66 public:
67  /// Create a new render queue
68  RenderQueue();
69 
70  /// Return the current number of jobs in the queue
71  inline size_t getJobCount() const { return m_jobs.size(); }
72 
73  /// Add a render job to the queue
74  void addJob(RenderJob *thr);
75 
76  /// Remove a (finished) render job from the queue
77  void removeJob(RenderJob *thr, bool wasCancelled);
78 
79  /// Return the amount of time spent rendering the given job (in seconds)
80  Float getRenderTime(const RenderJob *job) const;
81 
82  /// Register a render listener
83  void registerListener(RenderListener *listener);
84 
85  /// Unregister a render listener
86  void unregisterListener(RenderListener *listener);
87 
88  /**
89  * Wait until the queue contains a certain number
90  * of scenes (or less).
91  */
92  void waitLeft(size_t njobs) const;
93 
94  /// Releases resources held by recently finished jobs
95  void join() const;
96 
97  /// Cause all render jobs to write out the current image
98  void flush();
99 
100  /* Event distribution */
101  void signalWorkBegin(const RenderJob *job, const RectangularWorkUnit *wu, int worker);
102  void signalWorkEnd(const RenderJob *job, const ImageBlock *block, bool cancelled);
103  void signalWorkCanceled(const RenderJob *job, const Point2i &offset, const Vector2i &size);
104  void signalFinishJob(const RenderJob *job, bool cancelled);
105  void signalRefresh(const RenderJob *job);
106 
108 private:
109  /// Virtual destructor
110  virtual ~RenderQueue();
111 private:
112  struct JobRecord {
113  /* Only starting time for now */
114  unsigned int startTime;
115 
116  inline JobRecord() { }
117  inline JobRecord(unsigned int startTime)
118  : startTime(startTime) {
119  }
120  };
121 
122  std::map<RenderJob *, JobRecord> m_jobs;
123  mutable std::vector<RenderJob *> m_joinList;
124  mutable ref<Mutex> m_mutex, m_joinMutex;
125  mutable ref<ConditionVariable> m_cond;
126  ref<Timer> m_timer;
127  std::vector<RenderListener *> m_listeners;
128 };
129 
131 
132 #endif /* __MITSUBA_RENDER_RENDERQUEUE_H_ */
Render queue - used to keep track of a number of scenes that are simultaneously being rendered...
Definition: renderqueue.h:65
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
size_t getJobCount() const
Return the current number of jobs in the queue.
Definition: renderqueue.h:71
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Definition: fwd.h:99
Reference counting helper.
Definition: ref.h:40
Storage for an image sub-block (a.k.a render bucket)
Definition: imageblock.h:40
Work unit that specifies a rectangular region in an image.
Definition: rectwu.h:33
Coordinates the process of rendering a single image.
Definition: renderjob.h:37
Parent of all Mitsuba classes.
Definition: object.h:38
Abstract render listener - can be used to react to progress messages (e.g. in a GUI) ...
Definition: renderqueue.h:33
#define MTS_EXPORT_RENDER
Definition: platform.h:109
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138