forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_texture_pool.py
More file actions
202 lines (138 loc) · 6.01 KB
/
test_texture_pool.py
File metadata and controls
202 lines (138 loc) · 6.01 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from panda3d import core
import pytest
import tempfile
@pytest.fixture(scope='function')
def pool():
"This fixture ensures the pool is properly emptied"
pool = core.TexturePool
pool.release_all_textures()
yield pool
pool.release_all_textures()
def write_image(filename, channels):
img = core.PNMImage(1, 1, channels)
img.set_xel_a(0, 0, (0.0, 0.25, 0.5, 0.75))
assert img.write(filename)
@pytest.fixture(scope='session')
def image_rgb_path():
"Generates an RGB image."
file = tempfile.NamedTemporaryFile(suffix='-rgb.png')
path = core.Filename.from_os_specific(file.name)
path.make_true_case()
write_image(path, 3)
yield path
file.close()
@pytest.fixture(scope='session')
def image_rgba_path():
"Generates an RGBA image."
file = tempfile.NamedTemporaryFile(suffix='-rgba.png')
path = core.Filename.from_os_specific(file.name)
path.make_true_case()
write_image(path, 4)
yield path
file.close()
@pytest.fixture(scope='session')
def image_gray_path():
"Generates a grayscale image."
file = tempfile.NamedTemporaryFile(suffix='-gray.png')
path = core.Filename.from_os_specific(file.name)
path.make_true_case()
write_image(path, 1)
yield path
file.close()
def test_load_texture_rgba(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 4
def test_load_texture_rgba4(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path, 4)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 4
def test_load_texture_rgba3(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path, 3)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 3
def test_load_texture_rgba2(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path, 2)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 2
def test_load_texture_rgba1(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path, 1)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 1
def test_load_texture_rgb(pool, image_rgb_path):
tex = pool.load_texture(image_rgb_path)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 3
def test_load_texture_rgb4(pool, image_rgb_path):
# Will not increase this
tex = pool.load_texture(image_rgb_path, 4)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 3
def test_load_texture_rgb3(pool, image_rgb_path):
tex = pool.load_texture(image_rgb_path, 3)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 3
def test_load_texture_rgb2(pool, image_rgb_path):
# Cannot reduce this, since it would add an alpha channel
tex = pool.load_texture(image_rgb_path, 2)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 3
def test_load_texture_rgb1(pool, image_rgb_path):
tex = pool.load_texture(image_rgb_path, 1)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 1
def test_load_texture_rgba_alpha(pool, image_rgba_path, image_gray_path):
tex = pool.load_texture(image_rgba_path, image_gray_path)
assert tex.num_components == 4
def test_load_texture_rgba4_alpha(pool, image_rgba_path, image_gray_path):
tex = pool.load_texture(image_rgba_path, image_gray_path, 4)
assert tex.num_components == 4
def test_load_texture_rgba3_alpha(pool, image_rgba_path, image_gray_path):
tex = pool.load_texture(image_rgba_path, image_gray_path, 3)
assert tex.num_components == 4
def test_load_texture_rgba2_alpha(pool, image_rgba_path, image_gray_path):
#FIXME: why is this not consistent with test_load_texture_rgb2_alpha?
tex = pool.load_texture(image_rgba_path, image_gray_path, 2)
assert tex.num_components == 2
def test_load_texture_rgba1_alpha(pool, image_rgba_path, image_gray_path):
tex = pool.load_texture(image_rgba_path, image_gray_path, 1)
assert tex.num_components == 2
def test_load_texture_rgb_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path, image_gray_path)
assert tex.num_components == 4
def test_load_texture_rgb4_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path, image_gray_path, 4)
assert tex.num_components == 4
def test_load_texture_rgb3_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path, image_gray_path, 3)
assert tex.num_components == 4
def test_load_texture_rgb2_alpha(pool, image_rgb_path, image_gray_path):
#FIXME: why is this not consistent with test_load_texture_rgba2_alpha?
tex = pool.load_texture(image_rgb_path, image_gray_path, 2)
assert tex.num_components == 4
def test_load_texture_rgb1_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path, image_gray_path, 1)
assert tex.num_components == 2
def test_reload_texture_fewer_channels(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 4
tex = pool.load_texture(image_rgba_path, 3)
assert tex.num_components == 3
def test_reload_texture_more_channels(pool, image_rgba_path):
tex = pool.load_texture(image_rgba_path, 3)
assert pool.has_texture(image_rgba_path)
assert tex.num_components == 3
tex = pool.load_texture(image_rgba_path)
assert tex.num_components == 4
def test_reload_texture_with_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path)
assert pool.has_texture(image_rgb_path)
assert tex.num_components == 3
tex = pool.load_texture(image_rgb_path, image_gray_path)
assert tex.num_components == 4
def test_reload_texture_without_alpha(pool, image_rgb_path, image_gray_path):
tex = pool.load_texture(image_rgb_path, image_gray_path)
assert tex.num_components == 4
tex = pool.load_texture(image_rgb_path)
assert tex.num_components == 3