Skip to content

Commit

Permalink
Merge branch 'main' into feat_tracking_reference_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz authored Nov 15, 2024
2 parents e69487a + 74663e9 commit 3a019bb
Show file tree
Hide file tree
Showing 8 changed files with 1,487 additions and 1,390 deletions.
13 changes: 11 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Change Log

### 1.124 - 2024-12-01
### 1.124 - 2024-12-02

#### @cesium/engine

##### Additions :tada:

- Added `Entity.trackingReferenceFrame` property to allow tracking entities in their own inertial reference frame. [#12194](https://github.com/CesiumGS/cesium/pull/12194)

##### Fixes :wrench:

- Fix label rendering bug in WebGL1 contexts. [#12301](https://github.com/CesiumGS/cesium/pull/12301)

#### @cesium/widgets

##### Fixes :wrench:

- Added a `DeveloperError` when `globe` is set to `false` and a `baseLayer` is provided in `Viewer` options. This prevents errors caused by attempting to use a `baseLayer` without a globe. [#12274](https://github.com/CesiumGS/cesium/pull/12274)

### 1.123.1 - 2024-11-07

#### @cesium/engine
Expand Down Expand Up @@ -54,7 +64,6 @@

- Fix flickering issue caused by bounding sphere retrieval being blocked by the bounding sphere of another entity. [#12230](https://github.com/CesiumGS/cesium/pull/12230)
- Fixed `ImageBasedLighting.imageBasedLightingFactor` not affecting lighting. [#12129](https://github.com/CesiumGS/cesium/pull/12129)

- Fix error with normalization of corner points for lines and corridors with collinear points. [#12255](https://github.com/CesiumGS/cesium/pull/12255)

### 1.122 - 2024-10-01
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Javier Sanchez](https://github.com/jvrjsanchez)
- [Jérôme Fayot](https://github.com/jfayot)
- [Kirn Kim](https://github.com/squrki)
- [Emanuele Mastaglia](https://github.com/Masty88)
193 changes: 102 additions & 91 deletions packages/engine/Source/Renderer/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function loadBufferSource(texture, source) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

let arrayBufferView = source.arrayBufferView;
let { arrayBufferView } = source;
if (flipY) {
arrayBufferView = PixelFormat.flipY(
arrayBufferView,
Expand Down Expand Up @@ -386,6 +386,62 @@ function loadBufferSource(texture, source) {
}
}

/**
* Load texel data from a buffer into part of a texture
*
* @param {Texture} texture The texture to which texel values will be loaded.
* @param {TypedArray} arrayBufferView The texel values to be loaded into the texture.
* @param {number} xOffset The texel x coordinate of the lower left corner of the subregion of the texture to be updated.
* @param {number} yOffset The texel y coordinate of the lower left corner of the subregion of the texture to be updated.
* @param {number} width The width of the source data, in pixels.
* @param {number} width The height of the source data, in pixels.
*
* @private
*/
function loadPartialBufferSource(
texture,
arrayBufferView,
xOffset,
yOffset,
width,
height,
) {
const context = texture._context;
const gl = context._gl;

const { pixelFormat, pixelDatatype } = texture;

const unpackAlignment = PixelFormat.alignmentInBytes(
pixelFormat,
pixelDatatype,
width,
);
gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

if (texture.flipY) {
arrayBufferView = PixelFormat.flipY(
arrayBufferView,
pixelFormat,
pixelDatatype,
width,
height,
);
}
gl.texSubImage2D(
texture._textureTarget,
0,
xOffset,
yOffset,
width,
height,
pixelFormat,
PixelDatatype.toWebGLConstant(pixelDatatype, context),
arrayBufferView,
);
}

/**
* Load texel data from a framebuffer into a texture.
*
Expand Down Expand Up @@ -448,6 +504,35 @@ function loadImageSource(texture, source) {
);
}

/**
* Load texel data from an Image into part of a texture
*
* @param {Texture} texture The texture to which texel values will be loaded.
* @param {ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} source The source for texel values to be loaded into the texture.
* @param {number} xOffset The texel x coordinate of the lower left corner of the subregion of the texture to be updated.
* @param {number} yOffset The texel y coordinate of the lower left corner of the subregion of the texture to be updated.
*
* @private
*/
function loadPartialImageSource(texture, source, xOffset, yOffset) {
const context = texture._context;
const gl = context._gl;

gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);

gl.texSubImage2D(
texture._textureTarget,
0,
xOffset,
yOffset,
texture.pixelFormat,
PixelDatatype.toWebGLConstant(texture.pixelDatatype, context),
source,
);
}

/**
* Compute a dimension of the image for the next mip level.
*
Expand Down Expand Up @@ -812,7 +897,6 @@ Texture.prototype.copyFrom = function (options) {
gl.bindTexture(target, this._texture);

let { width, height } = source;
const arrayBufferView = source.arrayBufferView;

// Make sure we are using the element's intrinsic width and height where available
if (defined(source.videoWidth) && defined(source.videoHeight)) {
Expand All @@ -823,25 +907,6 @@ Texture.prototype.copyFrom = function (options) {
height = source.naturalHeight;
}

const textureWidth = this._width;
const textureHeight = this._height;
const internalFormat = this._internalFormat;
const pixelFormat = this._pixelFormat;
const pixelDatatype = this._pixelDatatype;

const preMultiplyAlpha = this._preMultiplyAlpha;
const flipY = this._flipY;

let unpackAlignment = 4;
if (defined(arrayBufferView)) {
unpackAlignment = PixelFormat.alignmentInBytes(
pixelFormat,
pixelDatatype,
width,
);
}
gl.pixelStorei(gl.UNPACK_ALIGNMENT, unpackAlignment);

if (skipColorSpaceConversion) {
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
} else {
Expand All @@ -853,94 +918,40 @@ Texture.prototype.copyFrom = function (options) {

let uploaded = false;
if (!this._initialized) {
let pixels;
if (
xOffset === 0 &&
yOffset === 0 &&
width === textureWidth &&
height === textureHeight
width === this._width &&
height === this._height
) {
// initialize the entire texture
if (defined(arrayBufferView)) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
if (flipY) {
pixels = PixelFormat.flipY(
arrayBufferView,
pixelFormat,
pixelDatatype,
textureWidth,
textureHeight,
);
} else {
pixels = arrayBufferView;
}
if (defined(source.arrayBufferView)) {
loadBufferSource(this, source);
} else {
// Only valid for DOM-Element uploads
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
pixels = source;
loadImageSource(this, source);
}
uploaded = true;
} else {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
// initialize the entire texture to zero
pixels = PixelFormat.createTypedArray(
pixelFormat,
pixelDatatype,
textureWidth,
textureHeight,
);
loadNull(this);
}
gl.texImage2D(
target,
0,
internalFormat,
textureWidth,
textureHeight,
0,
pixelFormat,
PixelDatatype.toWebGLConstant(pixelDatatype, context),
pixels,
);
this._initialized = true;
}

if (!uploaded) {
let pixels;
if (defined(arrayBufferView)) {
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);

if (flipY) {
pixels = PixelFormat.flipY(
arrayBufferView,
pixelFormat,
pixelDatatype,
width,
height,
);
} else {
pixels = arrayBufferView;
}
if (defined(source.arrayBufferView)) {
loadPartialBufferSource(
this,
source.arrayBufferView,
xOffset,
yOffset,
width,
height,
);
} else {
// Only valid for DOM-Element uploads
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
pixels = source;
loadPartialImageSource(this, source, xOffset, yOffset);
}
gl.texSubImage2D(
target,
0,
xOffset,
yOffset,
width,
height,
pixelFormat,
PixelDatatype.toWebGLConstant(pixelDatatype, context),
pixels,
);
}

gl.bindTexture(target, null);
Expand Down
27 changes: 23 additions & 4 deletions packages/engine/Source/Scene/SkyBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function SkyBox(options) {

this._attributeLocations = undefined;
this._useHdr = undefined;
this._hasError = false;
this._error = undefined;
}

/**
Expand Down Expand Up @@ -111,6 +113,15 @@ SkyBox.prototype.update = function (frameState, useHdr) {
return undefined;
}

// Throw any errors that had previously occurred asynchronously so they aren't
// ignored when running. See https://github.com/CesiumGS/cesium/pull/12307
if (this._hasError) {
const error = this._error;
this._hasError = false;
this._error = undefined;
throw error;
}

if (this._sources !== this.sources) {
this._sources = this.sources;
const sources = this.sources;
Expand Down Expand Up @@ -141,10 +152,18 @@ SkyBox.prototype.update = function (frameState, useHdr) {

if (typeof sources.positiveX === "string") {
// Given urls for cube-map images. Load them.
loadCubeMap(context, this._sources).then(function (cubeMap) {
that._cubeMap = that._cubeMap && that._cubeMap.destroy();
that._cubeMap = cubeMap;
});
loadCubeMap(context, this._sources)
.then(function (cubeMap) {
that._cubeMap = that._cubeMap && that._cubeMap.destroy();
that._cubeMap = cubeMap;
})
.catch((error) => {
// Defer throwing the error until the next call to update to prevent
// test from failing in `afterAll` if this is rejected after the test
// using the Skybox ends. See https://github.com/CesiumGS/cesium/pull/12307
this._hasError = true;
this._error = error;
});
} else {
this._cubeMap = this._cubeMap && this._cubeMap.destroy();
this._cubeMap = new CubeMap({
Expand Down
Loading

0 comments on commit 3a019bb

Please sign in to comment.