|
|
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;
|
}
|