-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture_test.cpp
127 lines (102 loc) · 3.02 KB
/
texture_test.cpp
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
120
121
122
123
124
125
126
127
#include <texture.h>
#include "../common.h"
using namespace scratchcpprender;
TEST(TextureTest, Constructors)
{
{
Texture tex;
ASSERT_EQ(tex.handle(), 0);
ASSERT_FALSE(tex.isValid());
ASSERT_EQ(tex.size().width(), 0);
ASSERT_EQ(tex.size().height(), 0);
ASSERT_EQ(tex.width(), 0);
ASSERT_EQ(tex.height(), 0);
}
{
Texture tex(2, QSize(4, 2));
ASSERT_EQ(tex.handle(), 2);
ASSERT_TRUE(tex.isValid());
ASSERT_EQ(tex.size().width(), 4);
ASSERT_EQ(tex.size().height(), 2);
ASSERT_EQ(tex.width(), 4);
ASSERT_EQ(tex.height(), 2);
}
{
Texture tex(2, 5, 8);
ASSERT_EQ(tex.handle(), 2);
ASSERT_TRUE(tex.isValid());
ASSERT_EQ(tex.size().width(), 5);
ASSERT_EQ(tex.size().height(), 8);
ASSERT_EQ(tex.width(), 5);
ASSERT_EQ(tex.height(), 8);
}
}
TEST(TextureTest, ToImage)
{
QOpenGLContext context;
context.create();
ASSERT_TRUE(context.isValid());
QOffscreenSurface surface;
surface.setFormat(context.format());
surface.create();
Q_ASSERT(surface.isValid());
context.makeCurrent(&surface);
QOpenGLExtraFunctions glF(&context);
glF.initializeOpenGLFunctions();
QOpenGLFramebufferObjectFormat format;
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
QOpenGLFramebufferObject fbo(80, 60, format);
fbo.bind();
QOpenGLPaintDevice device(fbo.size());
QPainter painter(&device);
painter.beginNativePainting();
painter.setRenderHint(QPainter::Antialiasing, false);
glF.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glF.glClear(GL_COLOR_BUFFER_BIT);
painter.drawEllipse(0, 0, fbo.width(), fbo.height());
painter.endNativePainting();
painter.end();
QImage image = fbo.toImage();
Texture tex(fbo.takeTexture(), fbo.width(), fbo.height());
ASSERT_EQ(tex.toImage(), image);
tex.release();
context.doneCurrent();
}
TEST(TextureTest, Release)
{
QOpenGLContext context;
context.create();
ASSERT_TRUE(context.isValid());
QOffscreenSurface surface;
surface.setFormat(context.format());
surface.create();
Q_ASSERT(surface.isValid());
context.makeCurrent(&surface);
QOpenGLExtraFunctions glF(&context);
glF.initializeOpenGLFunctions();
QOpenGLFramebufferObject fbo(1, 1);
GLuint handle = fbo.takeTexture();
ASSERT_TRUE(glF.glIsTexture(handle));
Texture tex(handle, fbo.width(), fbo.height());
ASSERT_TRUE(glF.glIsTexture(handle));
tex.release();
ASSERT_FALSE(glF.glIsTexture(handle));
ASSERT_FALSE(tex.isValid());
context.doneCurrent();
}
TEST(TextureTest, Operators)
{
Texture t1;
Texture t2;
ASSERT_TRUE(t1 == t2);
ASSERT_FALSE(t1 != t2);
Texture t3(3, 10, 10);
ASSERT_FALSE(t1 == t3);
ASSERT_TRUE(t1 != t3);
Texture t4(3, 10, 10);
ASSERT_TRUE(t3 == t4);
ASSERT_FALSE(t3 != t4);
Texture t5(2, 10, 10);
ASSERT_FALSE(t4 == t5);
ASSERT_TRUE(t4 != t5);
}