#ifndef __ABUFFER_HPP
#define __ABUFFER_HPP

#include "ssVector.hpp"
#include "color.h"
#include <vector>

class ABuffer
{
public:
	struct Fragment
	{
		Color		color;
		float		z;
		float		zmin;
		float		zmax;
		int			dotSign;
		float		weight;
		int			nextFragment;
	};

						ABuffer					(int width, int height, int subpixels);
						~ABuffer				(void);
	void				clear					(void);
	int					getWidth() const									{ return m_width; }
	int					getHeight() const									{ return m_height; }
	int					getSubpixels() const								{ return m_subpixels; }

	void				appendFragment			(int x, int y, int subpixel, const Fragment &f);

	void				collapseToFrameBuffer	(Color* frameBuffer, const Vector4 &background, bool zrange, float zthreshold);

	float				getAverageFragmentsPerPixel() const					{ return m_averageFragmentsPerPixel; }
	
private:
	int					m_width;
	int					m_height;
	int					m_subpixels;
	float				m_oofsubpixels;
	int*				m_firstFragments;
	std::vector<Fragment>	m_fragments;
	std::vector<Fragment *>	m_sortBuffer;
	int					m_firstFreeFragment;	
	int					m_fragmentsAllocated;
	float				m_averageFragmentsPerPixel;
};

#endif //__ABUFFER_HPP

