#ifndef QGLSLSHADER_H
#define QGLSLSHADER_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QVector3D>
#include <QMatrix4x4>
#include <QTime>
#include <QVector>
#include <QPushButton>

#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>

#include <QMutex>

#include <QOpenGLTexture>
#include <QOpenGLShader>

//QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)
//QT_FORWARD_DECLARE_CLASS(QOpenGLShader)
QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)

namespace SOPENGL
{
    class QGLSLShader : protected QOpenGLFunctions
    {
    public:
        QGLSLShader();
        virtual ~QGLSLShader();

        qreal GetAngle();
        qreal GetScale();

        QVector<QVector3D> GetVertices();
        QVector<QVector3D> GetNormals();

        virtual void CreateShader(const char* pSrcVShader, const char* pSrcFShader);
        virtual void CreateTexture(int nWidth, int nHeight, QOpenGLTexture::Target target, QOpenGLTexture::TextureFormat format);

        void Bind();
        void Release();

        virtual void SetUniformValue();

        virtual void EnableAttributeArray();
        virtual void SetAttributeBuffer();
        virtual void DisableAttributeArray();

        virtual void BindTexture();
        virtual void ReleaseTexture();

        virtual void Translate(float fX, float fY, float fZ);

        QOpenGLTexture *GetTexture();

        virtual void CreateGeometry();
        virtual void Quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);

    protected:
        qreal m_fAngle;
        qreal m_fScale;
        QVector<QVector3D> m_Vertices;
        QVector<QVector3D> m_Normals;

        QOpenGLShader* m_pVShader;
        QOpenGLShader* m_pFShader;
        QOpenGLShaderProgram* m_pProgram;

        int m_AttrVertex;
        int m_AttrNormal;
        int m_AttrTexCoord;
        int m_UniformMatrix;
        int m_UniformVideoTexture;

        int m_nTextureWidth;
        int m_nTextureHeight;


        QOpenGLTexture* m_pVideoTexture;
        QOpenGLBuffer m_VBO;
    };
}


#endif // QGLSLSHADER_H
