/***********      .---.         .-"-.      *******************\
* -------- *     /   ._.       / ´ ` \     * ---------------- *
* Author's *     \_  (__\      \_°v°_/     * humus@rogers.com *
*   note   *     //   \\       //   \\     * ICQ #47010716    *
* -------- *    ((     ))     ((     ))    * ---------------- *
*          ****--""---""-------""---""--****                  ********\
* 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 copy'n'pasted *
* 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/OpenGL/OpenGLApp.h"
#include "../Framework3/Util/Model.h"
#include "../Framework3/Util/BSP.h"
#include "../Framework3/Math/Scissor.h"

#define LIGHT_COUNT 3

class App : public OpenGLApp {
public:
	char *getTitle() const { return "Dynamic branching 3"; }

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

	bool init();
	void exit();

	bool load();
	void unload();

	void drawLights(const vec3 *lightPos, const vec3 *color, const vec3 &dx, const vec3 &dy);

	void drawZAmbient();
	void drawDepth(const vec3 *lightPos, const float *invRadius);
	void drawLighting(const vec3 *lightPos, const float *invRadius, const vec3 *color);

	void drawFrame();

protected:
	Model *map;
	BSP bsp;

	ShaderID preZSP, preZMP, plainTex, lightingSP[2][2], lightingMP[2][2], depth;
	TextureID base[4], bump[4], gloss[4], light, shadowMap, shadowMapDepth;
	SamplerStateID trilinearAniso;
	BlendStateID blendAdd, noColorWrite, colorMasks[LIGHT_COUNT];
	float parallax[4];

	CheckBox *useBranching, *useShadows, *useSinglePass, *animateLights;
};
