[svn] / nytr / trunk / libnytrengine / FrameBuffer.h Repository:
ViewVC logotype

View of /nytr/trunk/libnytrengine/FrameBuffer.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 840 - (download) (as text) (annotate)
Mon May 19 23:34:58 2008 UTC (2 years, 3 months ago) by kouhei
File size: 4284 byte(s)
unstable backup
#ifndef _nytr_FrameBuffer_h_
#define _nytr_FrameBuffer_h_

#include <fecti/Utility/FException.h>

#include "FilmFilter.h"

namespace nytr
{

class FilmBase
{
public:
	//! virtual D-tor
	virtual ~FilmBase();

	//! divide each pixel by sum of weight factor
	/*!
		@note
			must be called at the end of rendering to have proper result
	 */
	virtual void divideSumWeight() = 0;
};

//! Film class
/*!
	A 'film' is similar to 'channnels' in other softwares.
 */
template<typename T>
class Film : public FilmBase
{
public:
	//! C-tor
	/*!
		@param nIdx
			film index
		@param w
			film width
		@param h
			film height
		@param filtertype
			film filter type
	 */
	Film(unsigned int nIdx, unsigned int w, unsigned int h, FILMFILTERTYPE filtertype = FILMFILTER_DEFAULT, const T& fillColor = 0);

	//! D-tor
	~Film();

	//! direct film access
	T& operator()(int x, int y)
	{
		return (*m_ppmImpl)(x, y);
	}

	//! direct film access
	T& operator()(const fecti::FPoint& p)
	{
		return (*m_ppmImpl)(p);
	}

	//! add sample
	void addSample(const fecti::FVector2& p, const T& t, REAL fWeight = (REAL)1.0)
	{
		m_pFilmFilter->addSample(m_ppmImpl, m_ppmWeight, p, t, fWeight);
	}

	void divideSumWeight();

	// ------- accessor methods ------

	//! access pixmap buffer
	/*!
		use this method with care.
		if possible, use operator() or addSample() instead.
	 */
	fecti::FPixmap<T>* getpPM()
	{
		return m_ppmImpl;
	}

	const fecti::FPixmap<T>* getpPM() const
	{
		return m_ppmImpl;
	}

private:
	//! film index
	unsigned int m_nIdx;
	
	//! film data
	fecti::FPixmap<T>* m_ppmImpl;

	//! weight map
	/*!
		stores sum of weight per pixel.

		@see divideSumWeight()
	 */
	fecti::FPixmap<REAL>* m_ppmWeight;

	//! film FilmFilter
	FilmFilter<T>* m_pFilmFilter;
};

//! Frame Buffer class
/*!
	A framebuffer keeps track of all render output data for one frame.
 */
class FrameBuffer
{
public:
	enum
	{
		MAX_NUM_FILMS = 8,
	};

	//! C-tor
	/*!
		@param typePrimary
			type of primary film
		@param w
			film width
		@param h
			film height
		@param filtertype
			type of filter to use on primary film
	 */
	FrameBuffer(FILMTYPE typePrimary, unsigned int w, unsigned int h, FILMFILTERTYPE filtertype = FILMFILTER_DEFAULT);

	//! D-tor
	~FrameBuffer();

	//! add extra film
	/*!
		@param filmtype
			type of film to add

		@param filtertype
			filter type

		@return
			newly added film index

		@note
			access to this method is NOT multi-thread safe,
			because current nytr renderer impl. does not require this to be so.
	 */
	unsigned int addExFilm(FILMTYPE filmtype, FILMFILTERTYPE filtertype);

	//! add sample
	void addSample(const fecti::FVector2& vP, const SampleValue& val, REAL fScale = (REAL)1.0);

	//! do divideSumWeight() on each film
	/*!
		@see
			Film::divideSumWeight()
	 */
	void divideSumWeight();

	// ------ accessor methods ------
	FilmBase* getpFilm(unsigned int nIdx = 0)
	{
		FECTI_DBGASSERT(fecti::FEX_APPLICATION_ERROR, nIdx < m_nfilms);
		return m_arypfilm[nIdx];
	}

	const FilmBase* getpFilm(unsigned int nIdx = 0) const
	{
		FECTI_DBGASSERT(fecti::FEX_APPLICATION_ERROR, nIdx < m_nfilms);
		return m_arypfilm[nIdx];
	}

	unsigned int getnFilms() const
	{
		return m_nfilms;
	}

	FILMTYPE getType(unsigned int nIdx) const
	{
		return m_arytype[nIdx];
	}

	bool isAvailable(unsigned int nIdx) const
	{
		if(nIdx >= MAX_NUM_FILMS)
			return false;

		return m_arytype[nIdx] != FILM_UNUSED;
	}

	unsigned int getWidth() const
	{
		return m_nWidth;
	}

	unsigned int getHeight() const
	{
		return m_nHeight;
	}

	fecti::FPoint getSize() const
	{
		return fecti::FPoint(m_nWidth, m_nHeight);
	}

private:
	//! Film c-tor method
	FilmBase* newFilm(unsigned int nNewIdx, FILMTYPE filmtype, FILMFILTERTYPE filtertype);

	//! films
	FilmBase* m_arypfilm[MAX_NUM_FILMS];

	//! film type
	FILMTYPE m_arytype[MAX_NUM_FILMS];

	//! current number of films
	unsigned int m_nfilms;

	//! film width
	unsigned int m_nWidth;

	//! film height
	unsigned int m_nHeight;
};

} // end of namespace nytr

#include "FrameBuffer.inl.h"

#endif // _nytr_FrameBuffer_h_

admin
ViewVC Help
Powered by ViewVC 1.0.5