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
import { Texture } from "../../Source/Cesium.js";
import { TextureCache } from "../../Source/Cesium.js";
import createContext from "../createContext.js";
describe(
"Renderer/TextureCache",
function () {
var context;
beforeAll(function () {
context = createContext();
});
afterAll(function () {
context.destroyForSpecs();
});
it("adds and removes", function () {
var cache = new TextureCache();
var keyword = "texture";
var texture = new Texture({
context: context,
width: 1.0,
height: 1.0,
});
cache.addTexture(keyword, texture);
expect(cache._textures[keyword].count).toEqual(1);
expect(cache.numberOfTextures).toEqual(1);
texture.destroy();
expect(texture.isDestroyed()).toEqual(false);
expect(cache.numberOfTextures).toEqual(1);
cache.destroyReleasedTextures();
expect(texture.isDestroyed()).toEqual(true);
expect(cache.numberOfTextures).toEqual(0);
cache.destroy();
});
it("has a cache hit", function () {
var cache = new TextureCache(context);
var keyword = "texture";
var texture = new Texture({
context: context,
width: 1.0,
height: 1.0,
});
cache.addTexture(keyword, texture);
var texture2 = cache.getTexture(keyword);
expect(texture2).toBeDefined();
expect(texture).toBe(texture2);
expect(cache._textures[keyword].count).toEqual(2);
expect(cache.numberOfTextures).toEqual(1);
texture.destroy();
texture2.destroy();
cache.destroyReleasedTextures();
expect(texture.isDestroyed()).toEqual(true);
expect(cache.numberOfTextures).toEqual(0);
cache.destroy();
});
it("avoids thrashing", function () {
var cache = new TextureCache();
var keyword = "texture";
var texture = new Texture({
context: context,
width: 1.0,
height: 1.0,
});
cache.addTexture(keyword, texture);
texture.destroy();
var texture2 = cache.getTexture(keyword); // still a cache hit
cache.destroyReleasedTextures(); // does not destroy
expect(texture.isDestroyed()).toEqual(false);
expect(texture2.isDestroyed()).toEqual(false);
texture2.destroy();
cache.destroyReleasedTextures(); // destroys
expect(texture.isDestroyed()).toEqual(true);
expect(texture2.isDestroyed()).toEqual(true);
cache.destroy();
});
it("is destroyed", function () {
var cache = new TextureCache();
var keyword = "texture";
var texture = new Texture({
context: context,
width: 1.0,
height: 1.0,
});
cache.addTexture(keyword, texture);
cache.destroy();
expect(texture.isDestroyed()).toEqual(true);
expect(cache.isDestroyed()).toEqual(true);
});
it("is not destroyed", function () {
var cache = new TextureCache();
expect(cache.isDestroyed()).toEqual(false);
});
},
"WebGL"
);