2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
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
 
 
function clearColorTexture(wTexture) {
    if (wTexture._colorTexture && !wTexture._colorTexture.isDestroyed()) {
        wTexture._colorTexture.destroy();
    } else if (wTexture._colorTexture) {
        wTexture._colorTexture.destroy = function() {
            console.log('destroy')
        }
        wTexture._colorTexture = null;
    }
    if (wTexture._depthStencilTexture && !wTexture._depthStencilTexture.isDestroyed()) {
        wTexture._depthStencilTexture.destroy();
        wTexture._depthStencilTexture = null;
    }
}
function clearFramebuffer(wTexture) {
    if (wTexture._framebuffer && !wTexture._framebuffer.isDestroyed()) {
        wTexture._framebuffer.destroy();
        wTexture._framebuffer = null;
    }
}
function createTexture(wTexture, context, width, height) {
    clearColorTexture(wTexture);
    clearFramebuffer(wTexture);
    wTexture._colorTexture = new Cesium.Texture({
        context: context,
        width: width,
        height: height,
        pixelFormat: Cesium.PixelFormat.RGBA,
        pixelDatatype: Cesium.PixelDatatype.UNSIGNED_BYTE
    });
 
    wTexture._depthStencilTexture = new Cesium.Texture({
        context: context,
        width: width,
        height: height,
        pixelFormat: Cesium.PixelFormat.DEPTH_STENCIL,
        pixelDatatype: Cesium.PixelDatatype.UNSIGNED_INT_24_8
    });
 
    wTexture._framebuffer = new Cesium.Framebuffer({
        context: context,
        colorTextures: [wTexture._colorTexture],
        depthStencilTexture: wTexture._depthStencilTexture,
        destroyAttachments: null
    });
}
 
function WaterTexture() {
    this._framebuffer = null;
    this._colorTexture = null;
    this._textureChangedEvent = new Cesium.Event();
}
 
WaterTexture.prototype.getTextureChangedEvent = function() {
    return this._textureChangedEvent;
}
WaterTexture.prototype.update = function(context, width, height) {
    var colorTexture = this._colorTexture;
    let changed = false;
    if (!Cesium.defined(colorTexture) || colorTexture.width !== width || colorTexture.height !== height) {
        changed = true;
    }
    if (!Cesium.defined(this._framebuffer) && changed) {
        createTexture(this, context, width, height);
        this._textureChangedEvent.raiseEvent(this._colorTexture);
    }
}
 
WaterTexture.prototype.isDestroyed = function() {
    return false;
}
 
WaterTexture.prototype.destroy = function() {
    clearColorTexture(this);
    clearFramebuffer(this);
    return;
}