summaryrefslogtreecommitdiff
path: root/src/glwidget.h
blob: 71199d19d78837828929befd13ebcd5b6e7cb225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once

#ifdef __APPLE__
#define GL_SILENCE_DEPRECATION
#endif

#include "arap.h"
#include "graphics/camera.h"
#include "graphics/shader.h"

#include <QOpenGLWidget>
#include <QElapsedTimer>
#include <QTimer>
#include <memory>

struct TextureData{
    GLuint textureID;
    int width;
    int height;
};

class GLWidget : public QOpenGLWidget
{
    Q_OBJECT

public:
    GLWidget(QWidget *parent = nullptr);
    ~GLWidget();

private:
    static const int FRAMES_TO_AVERAGE = 30;

    Eigen::Vector3f transformToWorldRay(int x, int y);

    // Basic OpenGL Overrides
    void initializeGL()         override;
    void paintGL()              override;
    void resizeGL(int w, int h) override;

    // Event Listeners
    void mousePressEvent  (QMouseEvent *event) override;
    void mouseMoveEvent   (QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void wheelEvent       (QWheelEvent *event) override;
    void keyPressEvent    (QKeyEvent   *event) override;
    void keyReleaseEvent  (QKeyEvent   *event) override;

    TextureData loadTextureFromFile(const char *path);
    void makeFBO();
    void initFullScreenQuad();
    void paintTexture(GLuint texture, bool postProcessOn);





private slots:
    // Physics Tick
    void tick();

private:
    ARAP    m_arap;
    Camera  m_camera;
    Shader *m_defaultShader;
    Shader *m_pointShader;

    float m_movementScaling;
    float m_vertexSelectionThreshold;
    float m_vSize;

    // Timing
    QElapsedTimer m_deltaTimeProvider; // For measuring elapsed time
    QTimer        m_intervalTimer;     // For triggering timed events

    // Movement
    int m_forward;
    int m_sideways;
    int m_vertical;

    // Mouse handler stuff
    int m_lastX;
    int m_lastY;
    bool m_leftCapture;
    bool m_rightCapture;
    SelectMode m_rightClickSelectMode;
    int m_lastSelectedVertex = -1;


    int m_devicePixelRatio;
      GLuint m_defaultFBO;
      int m_fbo_width;
      int m_fbo_height;
      int m_screen_width;
      int m_screen_height;

        GLuint m_fullscreen_vbo;
        GLuint m_fullscreen_vao;
        GLuint m_fbo;
        GLuint m_fbo_texture;
        GLuint m_fbo_renderbuffer;
    GLuint m_texture0;

    std::vector<GLfloat> fullscreen_quad_data =
     { //     POSITIONS    //
         -1.f,  1.f, 0.0f,
          0.f, 1.f, //uv
         -1.f, -1.f, 0.0f,
          0.f, 0.f, //uv
          1.f, -1.f, 0.0f,
          1.f, 0.f, //uv
          1.f,  1.f, 0.0f,
          1.f, 1.f, //uv
         -1.f,  1.f, 0.0f,
          0.f, 1.f, //uv
          1.f, -1.f, 0.0f,
          1.f, 0.f //uv
     };

};