//=============================================================================
// FILE: app.h
//
//                  Copyright (c) 2017 QUALCOMM Technologies Inc.
//                              All Rights Reserved.
//
//=============================================================================

#pragma once

#include "../../common/spatialaudio_common.h"
#include <glm/glm.hpp>


class Q3DSoundChannelCrossFader
{
public:
	Q3DSoundChannelCrossFader() {};
	void Update(const float elapsedTime);
	void Stop();
	void Play(
		q3d_audio_client*const pSpatialAudio,
		Q3DSound* pSounds,
		Q3DSoundCrossFaderCommon::StopSoundFunctionPtr stopSound,
		const float soundsNum,
		const float timeToPlay,
		const float timeToCrossfade);

	q3d_audio_sound_id GetSoundCurrentIndex() { return mCommon.mSoundCurrentIndex; }
    Q3DSoundCrossFaderCommon::State GetCurrentState() const { return mCommon.mState; }

private:
	Q3DSoundCrossFaderCommon mCommon;
};

class SoundChannel : public SpatialAudioCommon
{
	virtual void Initialize();
	virtual void Shutdown();

protected:
	virtual void OnTouchScreen();
	virtual void RenderModelCallback(int whichEye, float elapsedTime);
	virtual void RenderCallback(float elapsedTime);

private:
	#define						SPATIAL_AUDIO_SOUND_CHANNEL_NUM 3
	Q3DSound					mSoundChannel[SPATIAL_AUDIO_SOUND_CHANNEL_NUM];
	Q3DSoundChannelCrossFader	mSoundChannelCrossFader;
	int							mSoundLastPlayedIndex;

	enum { kGazeBoxSoundchannelNum = kGazeBoxMiscNum };
	Svr::SvrGeometry*           mpGazeBoxModel;
	Svr::SvrShader              mGazeBoxShader;
	GLuint						mGazeBoxTexture[kGazeBoxSoundchannelNum];
    GLuint                      mGazeBoxTextureSampler;
	bool						mGazeBoxActive[kGazeBoxSoundchannelNum];
	float						mGazeBoxLastHsvSaturation[kGazeBoxSoundchannelNum];
	float						mGazeBoxLastHsvValue[kGazeBoxSoundchannelNum];

	Svr::SvrGeometry*           mpSkyModel;
	Svr::SvrShader              mSkyShader;

	Svr::SvrGeometry*           mpFloorModel;
	Svr::SvrShader              mFloorShader;
};