/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef FPSCOUNTER_H
#define FPSCOUNTER_H
#include "time.h"
#include "Font.h"
#include "Shaders.h"
#include "Common.h"
#include "glm/gtx/transform.hpp"
#include "glm/gtc/matrix_inverse.hpp"
#include <glm/gtc/type_ptr.hpp>

#ifdef _WIN32
#include "windows.h"
#endif
using namespace glTF;

#if 1
#define VERTSHADER "../Resource/font2D.vert"
#define FRAGSHADER "../Resource/font2D.frag"
#define FONTPATH "../Resource/DejaVuSans.ttf"
#else
#define VERTSHADER "./font2D.vert"
#define FRAGSHADER "./font2D.frag"
#define FONTPATH "./DejaVuSans.ttf"
#endif
class FPSCounter
{
public:
    void timeStampStart();
    void timeStampEnd();

    void gpuTimeStampStart();
    void gpuTimeStampEnd();
    void gpuTimeAccumulation();
    void gpuAccumulationTimeclear();


    void printFPS( glTFViewport* pViewpoit );
    bool loadFPSShader(ShaderProgram* pShaderProgram);

    FPSCounter()
    {
        pFont = new Font();
        pFont->loadFont(FONTPATH,32);
        mFPS=0;
        mDurationTime =0;
        mGPUTime =0;
        mTotalTime = 0;
        QueryPerformanceFrequency(&f);
        dqFreq=(double)f.QuadPart;
    }
    ~FPSCounter()
    {
        if (pFont!=NULL)
        {
            pFont->deleteFont();
        }
        glDeleteProgram(uiFPSProgram);
        
    }
    
private:
    int getFPS();
    double getExecutionTime();
    double getGPUTime();
    Font* pFont;

    unsigned int uiFPSProgram;
#ifdef _WIN32
    double mStartTime;
    double mEndTime;
    double mDurationTime;
    double dqFreq;               
    LARGE_INTEGER f; 

    double mGPUDuration;
    double mGPUStartTime;
    double mGPUEndTime;
    double mGPUTime;
    double mTotalTime;
#else
    clock_t mStartTime;
    clock_t mEndTime;
    clock_t mDurationTime;

    clock_t mGPUDuration;
    clock_t mGPUStartTime;
    clock_t mGPUEndTime;
    double mGPUTime;
    double mTotalTime;
#endif

    int mFPS;
};

#endif