
/* * * * * * * * * * * * * Author's note * * * * * * * * * * * *\
*   _       _   _       _   _       _   _       _     _ _ _ _   *
*  |_|     |_| |_|     |_| |_|_   _|_| |_|     |_|  _|_|_|_|_|  *
*  |_|_ _ _|_| |_|     |_| |_|_|_|_|_| |_|     |_| |_|_ _ _     *
*  |_|_|_|_|_| |_|     |_| |_| |_| |_| |_|     |_|   |_|_|_|_   *
*  |_|     |_| |_|_ _ _|_| |_|     |_| |_|_ _ _|_|  _ _ _ _|_|  *
*  |_|     |_|   |_|_|_|   |_|     |_|   |_|_|_|   |_|_|_|_|    *
*                                                               *
*                     http://www.humus.name                     *
*                                                                *
* This file is a part of the work done by Humus. You are free to   *
* use the code in any way you like, modified, unmodified or copied   *
* into your own work. However, I expect you to respect these points:  *
*  - If you use this file and its contents unmodified, or use a major *
*    part of this file, please credit the author and leave this note. *
*  - For use in anything commercial, please request my approval.     *
*  - Share your work and ideas too as much as you can.             *
*                                                                *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "../Framework3/Direct3D10/D3D10App.h"
#include "../Framework3/Util/Model.h"
#include "../Framework3/Util/BSP.h"
#include "../Framework3/Math/Noise.h"

struct Light
{
	float3 position;
	float radius;
};

struct Edge
{
	Edge(const uint i0, const uint i1)
	{
		index0 = min(i0, i1);
		index1 = max(i0, i1);
	}

	uint index0, index1;
	vec3 normal;
	bool remove;
};

struct Vertex
{
	float3 v0;
	float3 v1;
};


#define LIGHT_COUNT 19

class App : public D3D10App
{
public:
	char *getTitle() const { return "Geometric Post-process Anti-Aliasing"; }

	void moveCamera(const float3 &dir);
	void resetCamera();

	bool onKey(const uint key, const bool pressed);
	void onSize(const int w, const int h);

	bool init();
	void exit();

	bool initAPI();
	void exitAPI();

	bool load();
	void unload();

	void drawFrame();

protected:
	ShaderID m_FillBuffers, m_Ambient, m_Lighting, m_AntiAlias;

	TextureID m_BaseTex[5], m_BumpTex[5];
	TextureID m_BaseRT, m_NormalRT, m_DepthRT;

	SamplerStateID m_BaseFilter, m_PointClamp;
	BlendStateID m_BlendAdd;
	DepthStateID m_DepthTest;
	RasterizerStateID m_CullBack_DepthBias;

	Light m_Lights[LIGHT_COUNT];

	Model *m_Map;
	Model *m_Sphere;
	BSP m_BSP;

	VertexFormatID m_EdgesVF;
	VertexBufferID m_EdgesVB;
	uint m_EdgesVertexCount;

	CheckBox *m_UseGPAA;
};
