-
Notifications
You must be signed in to change notification settings - Fork 35
/
surfaceitem.h
117 lines (91 loc) · 3.09 KB
/
surfaceitem.h
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
/*
* Copyright (c) 2012 Samuel Rødal
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef SURFACEITEM_H
#define SURFACEITEM_H
#include <QImage>
#include <QTime>
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QPropertyAnimation>
class Camera;
class Map;
class WaylandSurface;
class QOpenGLShaderProgram;
class SurfaceItem : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
public:
SurfaceItem(WaylandSurface *surface);
~SurfaceItem();
QVector<QVector3D> vertices() const;
WaylandSurface *surface() const
{
return m_surface;
}
void setPos(const QVector3D &pos) { m_pos = pos; }
void setNormal(const QVector3D &normal) { m_normal = normal; }
void setDepthOffset(qreal offset) { m_depthOffset = offset; }
qreal depthOffset() const { return m_depthOffset; }
qreal height() const;
qreal maxHeight() const;
void setFocus(bool focus);
void setHeight(qreal height);
void setMipmap(bool mipmap) { m_mipmap = mipmap; }
uint textureId() const;
QSize size() const;
void render(const Map &map, const Camera &camera) const;
void setOpacity(qreal op);
qreal opacity() const { return m_opacity; }
static void initialize(const Map &map, QObject *parent);
private slots:
void surfaceDamaged(const QRect &rect);
void sizeChanged();
signals:
void opacityChanged();
private:
WaylandSurface *m_surface;
QVector3D m_pos;
QVector3D m_normal;
qreal m_depthOffset;
qreal m_opacity;
static QOpenGLShaderProgram *m_program;
static uint m_vertexAttr;
static uint m_texCoordAttr;
static uint m_matrixUniform;
static uint m_pixelSizeUniform;
static uint m_eyeUniform;
static uint m_normalUniform;
static uint m_lightsUniform;
static uint m_numLightsUniform;
static uint m_focusColorUniform;
uint m_textureId;
QRect m_dirty;
QSize m_textureSize;
QTime m_time;
qreal m_height;
bool m_focus;
bool m_mipmap;
QPropertyAnimation *m_opacityAnimation;
};
#endif