2011-08-19 15:13:18 +08:00
|
|
|
\part{Development guide}
|
2010-10-31 23:06:26 +08:00
|
|
|
This chapter and the subsequent ones will provide an overview
|
2012-10-25 02:44:26 +08:00
|
|
|
of the the coding conventions and general architecture of Mitsuba.
|
|
|
|
You should only read them if if you wish to interface with the API
|
2010-10-31 23:06:26 +08:00
|
|
|
in some way (e.g. by developing your own plugins). The coding style
|
2011-08-19 15:13:18 +08:00
|
|
|
section is only relevant if you plan to submit patches that are meant
|
|
|
|
to become part of the main codebase.
|
2010-10-31 23:06:26 +08:00
|
|
|
|
2011-08-19 15:13:18 +08:00
|
|
|
\section{Code structure}
|
|
|
|
Mitsuba is split into four basic support libraries:
|
|
|
|
\begin{itemize}
|
2012-10-25 02:44:26 +08:00
|
|
|
\item The core library (\code{libcore}) implements basic functionality such as
|
2014-02-06 22:11:30 +08:00
|
|
|
cross-platform file and bitmap I/O, data structures, scheduling, as well as logging and plugin management.
|
2012-10-25 02:44:26 +08:00
|
|
|
\item The rendering library (\code{librender}) contains abstractions
|
2014-02-06 22:11:30 +08:00
|
|
|
needed to load and represent scenes containing light sources, shapes, materials, and participating media.
|
2011-08-19 15:13:18 +08:00
|
|
|
\item The hardware acceleration library (\code{libhw})
|
2014-02-06 22:11:30 +08:00
|
|
|
implements a cross-platform display library, an object-oriented OpenGL
|
|
|
|
wrapper, as well as support for rendering interactive previews of scenes.
|
2011-08-19 15:13:18 +08:00
|
|
|
\item Finally, the bidirectional library (\code{libbidir})
|
2014-02-06 22:11:30 +08:00
|
|
|
contains a support layer that is used to implement bidirectional rendering algorithms such as
|
|
|
|
Bidirectional Path Tracing and Metropolis Light Transport.
|
2011-08-19 15:13:18 +08:00
|
|
|
\end{itemize}
|
|
|
|
A detailed reference of these APIs is available at
|
|
|
|
\url{http://www.mitsuba-renderer.org/api}. The next sections
|
|
|
|
present a few basic examples to get familiar with them.
|
|
|
|
|
|
|
|
\section{Coding style}
|
2012-10-25 02:44:26 +08:00
|
|
|
\paragraph{Indentation:} The Mitsuba codebase uses tabs for indentation,
|
2010-10-31 23:06:26 +08:00
|
|
|
which expand to \emph{four} spaces. Please make sure that you configure your editor
|
|
|
|
this way, otherwise the source code layout will look garbled.
|
|
|
|
|
2012-10-25 02:44:26 +08:00
|
|
|
\paragraph{Placement of braces:} Opening braces should be placed on the
|
2010-10-31 23:06:26 +08:00
|
|
|
same line to make the best use of vertical space, i.e.
|
|
|
|
\begin{cpp}
|
|
|
|
if (x > y) {
|
2014-02-06 22:11:30 +08:00
|
|
|
x = y;
|
2010-10-31 23:06:26 +08:00
|
|
|
}
|
|
|
|
\end{cpp}
|
|
|
|
|
|
|
|
\paragraph{Placement of spaces:} Placement of spaces follows K\&R, e.g.
|
|
|
|
\begin{cpp}
|
|
|
|
if (x == y) {
|
2014-02-06 22:11:30 +08:00
|
|
|
..
|
2010-10-31 23:06:26 +08:00
|
|
|
} else if (x > y) {
|
2014-02-06 22:11:30 +08:00
|
|
|
..
|
2010-10-31 23:06:26 +08:00
|
|
|
} else {
|
2014-02-06 22:11:30 +08:00
|
|
|
..
|
2010-10-31 23:06:26 +08:00
|
|
|
}
|
|
|
|
\end{cpp}
|
|
|
|
rather than things like this
|
|
|
|
\begin{cpp}
|
|
|
|
if ( x==y ){
|
|
|
|
}
|
|
|
|
..
|
|
|
|
\end{cpp}
|
|
|
|
|
2012-10-25 02:44:26 +08:00
|
|
|
\paragraph{Name format:} Names are always written in camel-case.
|
2010-10-31 23:06:26 +08:00
|
|
|
Classes and structures start with a capital letter, whereas member functions
|
2012-10-25 02:44:26 +08:00
|
|
|
and attributes start with a lower-case letter. Attributes of classes
|
2010-10-31 23:06:26 +08:00
|
|
|
have the prefix \code{m\_}. Here is an example:
|
|
|
|
\begin{cpp}
|
|
|
|
class MyClass {
|
|
|
|
public:
|
2014-02-06 22:11:30 +08:00
|
|
|
MyClass(int value) : m_value(value) { }
|
2010-10-31 23:06:26 +08:00
|
|
|
|
2014-02-06 22:11:30 +08:00
|
|
|
inline void setValue(int value) { m_value = value; }
|
|
|
|
inline int getValue() const { return m_value; }
|
2010-10-31 23:06:26 +08:00
|
|
|
private:
|
2014-02-06 22:11:30 +08:00
|
|
|
int m_value;
|
2010-10-31 23:06:26 +08:00
|
|
|
};
|
|
|
|
\end{cpp}
|
|
|
|
|
|
|
|
\paragraph{Enumerations:} For clarity, both enumerations types and entries
|
|
|
|
start with a capital \textbf{E}, e.g.
|
|
|
|
\begin{cpp}
|
|
|
|
enum ETristate {
|
2014-02-06 22:11:30 +08:00
|
|
|
ENo = 0,
|
|
|
|
EYes,
|
|
|
|
EMaybe
|
2010-10-31 23:06:26 +08:00
|
|
|
};
|
|
|
|
\end{cpp}
|
|
|
|
\paragraph{Constant methods and parameters:} Declare member functions and
|
|
|
|
their parameters as \code{const} whenever this is possible
|
|
|
|
and properly conveys the semantics.
|
|
|
|
\paragraph{Inline methods:} Always inline trivial pieces of code, such
|
|
|
|
as getters and setters.
|
|
|
|
\paragraph{Documentation:} Headers files should contain
|
|
|
|
Doxygen-compatible documentation. It is also a good idea to add
|
2012-10-25 02:44:26 +08:00
|
|
|
comments to a \code{.cpp} file to explain subtleties of an implemented algorithm.
|
2010-10-31 23:06:26 +08:00
|
|
|
However, anything pertaining to the API should go into the header file.
|
|
|
|
|
|
|
|
\paragraph{Boost:} Use the boost libraries whenever this helps to save
|
|
|
|
time or write more compact code.
|
|
|
|
|
2011-08-19 15:13:18 +08:00
|
|
|
\paragraph{Classes vs structures:}In Mitsuba, classes usually go onto the heap,
|
2012-10-25 02:44:26 +08:00
|
|
|
whereas structures may be allocated both on the stack and the heap.
|
2010-10-31 23:06:26 +08:00
|
|
|
|
2011-08-19 15:13:18 +08:00
|
|
|
Classes that derive from \code{Object} implement a protected virtual
|
2010-10-31 23:06:26 +08:00
|
|
|
deconstructor, which explicitly prevents them from being allocated on the stack.
|
|
|
|
The only way they can be deallocated is using the built-in reference
|
|
|
|
counting. This is done using the \code{ref<>} template, e.g.
|
|
|
|
|
|
|
|
\begin{cpp}
|
|
|
|
if (..) {
|
2014-02-06 22:11:30 +08:00
|
|
|
ref<MyClass> instance = new MyClass();
|
|
|
|
instance->doSomething()
|
2010-10-31 23:06:26 +08:00
|
|
|
} // reference expires, instance will be deallocated
|
|
|
|
\end{cpp}
|
|
|
|
|
|
|
|
\paragraph{Separation of plugins:}Mitsuba encourages that plugins are only
|
|
|
|
used via the generic interface they implement. You will find that almost all plugins
|
2012-09-28 00:43:51 +08:00
|
|
|
(e.g. emitters) don't actually provide a header file, hence they can only be accessed
|
2012-10-25 02:44:26 +08:00
|
|
|
using the generic \code{Emitter} interface they implement. If any kind of special
|
|
|
|
interaction between plugins is needed, this is usually an indication that the
|
2010-10-31 23:06:26 +08:00
|
|
|
generic interface should be extended to accomodate this.
|