Skip to content

Commit cb7fe95

Browse files
authored
Merge pull request #12701 from Hiwen/Textrue3D-wrapR
Add wrapR property to Sampler and Texture3D
2 parents f3c8e8c + b04a0cd commit cb7fe95

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

Apps/Sandcastle/gallery/development/VolumeCloud.html renamed to Apps/Sandcastle/gallery/VolumeCloud.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
name="description"
1212
content="Rendering Volume Cloud with Texture3D and Custom GLSL. Transplanted from Three.js"
1313
/>
14-
<meta name="cesium-sandcastle-labels" content="Development" />
14+
<meta name="cesium-sandcastle-labels" content="Tutorials,Showcases" />
1515
<title>Cesium Demo</title>
1616
<script type="text/javascript" src="../Sandcastle-header.js"></script>
1717
<script
File renamed without changes.

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#### Additions :tada:
2222

2323
- Expand the CustomShader Sample to support real-time modification of CustomShader. [#12702](https://github.com/CesiumGS/cesium/pull/12702)
24+
- Add wrapR property to Sampler and Texture3D, to support the newly added third dimension wrap.[#12701](https://github.com/CesiumGS/cesium/pull/12701)
2425

2526
## 1.131 - 2025-07-01
2627

packages/engine/Source/Renderer/Sampler.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function Sampler(options) {
1313
options = options ?? Frozen.EMPTY_OBJECT;
1414

1515
const {
16+
wrapR = TextureWrap.CLAMP_TO_EDGE,
1617
wrapS = TextureWrap.CLAMP_TO_EDGE,
1718
wrapT = TextureWrap.CLAMP_TO_EDGE,
1819
minificationFilter = TextureMinificationFilter.LINEAR,
@@ -21,6 +22,10 @@ function Sampler(options) {
2122
} = options;
2223

2324
//>>includeStart('debug', pragmas.debug);
25+
if (!TextureWrap.validate(wrapR)) {
26+
throw new DeveloperError("Invalid sampler.wrapR.");
27+
}
28+
2429
if (!TextureWrap.validate(wrapS)) {
2530
throw new DeveloperError("Invalid sampler.wrapS.");
2631
}
@@ -44,6 +49,7 @@ function Sampler(options) {
4449
);
4550
//>>includeEnd('debug');
4651

52+
this._wrapR = wrapR;
4753
this._wrapS = wrapS;
4854
this._wrapT = wrapT;
4955
this._minificationFilter = minificationFilter;
@@ -52,6 +58,11 @@ function Sampler(options) {
5258
}
5359

5460
Object.defineProperties(Sampler.prototype, {
61+
wrapR: {
62+
get: function () {
63+
return this._wrapR;
64+
},
65+
},
5566
wrapS: {
5667
get: function () {
5768
return this._wrapS;
@@ -84,6 +95,7 @@ Sampler.equals = function (left, right) {
8495
left === right ||
8596
(defined(left) &&
8697
defined(right) &&
98+
left._wrapR === right._wrapR &&
8799
left._wrapS === right._wrapS &&
88100
left._wrapT === right._wrapT &&
89101
left._minificationFilter === right._minificationFilter &&
@@ -94,6 +106,7 @@ Sampler.equals = function (left, right) {
94106

95107
Sampler.NEAREST = Object.freeze(
96108
new Sampler({
109+
wrapR: TextureWrap.CLAMP_TO_EDGE,
97110
wrapS: TextureWrap.CLAMP_TO_EDGE,
98111
wrapT: TextureWrap.CLAMP_TO_EDGE,
99112
minificationFilter: TextureMinificationFilter.NEAREST,

packages/engine/Source/Renderer/Texture3D.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,30 @@ import Sampler from "./Sampler.js";
1313
import TextureMagnificationFilter from "./TextureMagnificationFilter.js";
1414
import TextureMinificationFilter from "./TextureMinificationFilter.js";
1515

16+
/**
17+
* @typedef {object} Texture3D.Source
18+
* @property {number} width The width (in pixels) of the 3D texture source data.
19+
* @property {number} height The height (in pixels) of the 3D texture source data.
20+
* @property {number} depth The depth (in pixels) of the 3D texture source data.
21+
* @property {TypedArray|DataView} arrayBufferView The source data for a 3D texture. The type of each element needs to match the pixelDatatype.
22+
* @property {TypedArray|DataView} [mipLevels] An array of mip level data. Each element in the array should be a TypedArray or DataView that matches the pixelDatatype.
23+
*/
24+
1625
/**
1726
* @typedef {object} Texture3D.ConstructorOptions
1827
*
1928
* @property {Context} context
20-
* @property {object} [source] The source for texel values to be loaded into the texture3D.
29+
* @property {Texture3D.Source} [source] The source for texel values to be loaded into the 3D texture.
2130
* @property {PixelFormat} [pixelFormat=PixelFormat.RGBA] The format of each pixel, i.e., the number of components it has and what they represent.
2231
* @property {PixelDatatype} [pixelDatatype=PixelDatatype.UNSIGNED_BYTE] The data type of each pixel.
2332
* @property {boolean} [flipY=true] If true, the source values will be read as if the y-axis is inverted (y=0 at the top).
2433
* @property {boolean} [skipColorSpaceConversion=false] If true, color space conversions will be skipped when reading the texel values.
25-
* @property {Sampler} [sampler] Information about how to sample the texture3D.
26-
* @property {number} [width] The pixel width of the texture3D. If not supplied, must be available from the source.
27-
* @property {number} [height] The pixel height of the texture3D. If not supplied, must be available from the source.
28-
* @property {number} [depth] The pixel depth of the texture3D. If not supplied, must be available from the source.
34+
* @property {Sampler} [sampler] Information about how to sample the 3D texture.
35+
* @property {number} [width] The width (in pixels) of the 3D texture. If not supplied, must be available from the source.
36+
* @property {number} [height] The height (in pixels) of the 3D texture. If not supplied, must be available from the source.
37+
* @property {number} [depth] The depth (in pixels) of the 3D texture. If not supplied, must be available from the source.
2938
* @property {boolean} [preMultiplyAlpha] If true, the alpha channel will be multiplied into the other channels.
30-
* @property {string} [id] A unique identifier for the texture3D. If this is not given, then a GUID will be created.
39+
* @property {string} [id] A unique identifier for the 3D texture. If this is not given, then a GUID will be created.
3140
*
3241
* @private
3342
*/
@@ -253,7 +262,7 @@ function Texture3D(options) {
253262
* Load texel data from a buffer into a texture3D.
254263
*
255264
* @param {Texture3D} texture3D The texture3D to which texel values will be loaded.
256-
* @param {object} source The source for texel values to be loaded into the texture3D.
265+
* @param {Texture3D.Source} source The source for texel values to be loaded into the texture3D.
257266
*
258267
* @private
259268
*/
@@ -503,6 +512,7 @@ function setupSampler(texture3D, sampler) {
503512
gl.bindTexture(target, texture3D._texture);
504513
gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, minificationFilter);
505514
gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, magnificationFilter);
515+
gl.texParameteri(target, gl.TEXTURE_WRAP_R, sampler.wrapR);
506516
gl.texParameteri(target, gl.TEXTURE_WRAP_S, sampler.wrapS);
507517
gl.texParameteri(target, gl.TEXTURE_WRAP_T, sampler.wrapT);
508518
if (defined(texture3D._textureFilterAnisotropic)) {

packages/engine/Specs/Renderer/SamplerSpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe(
2121

2222
it("has expected default values", function () {
2323
const sampler = new Sampler();
24+
expect(sampler.wrapR).toEqual(TextureWrap.CLAMP_TO_EDGE);
2425
expect(sampler.wrapS).toEqual(TextureWrap.CLAMP_TO_EDGE);
2526
expect(sampler.wrapT).toEqual(TextureWrap.CLAMP_TO_EDGE);
2627
expect(sampler.minificationFilter).toEqual(
@@ -32,6 +33,14 @@ describe(
3233
expect(sampler.maximumAnisotropy).toEqual(1.0);
3334
});
3435

36+
it("throws when creating a sampler with invalid wrapR", function () {
37+
expect(function () {
38+
return new Sampler({
39+
wrapR: "invalid wrap",
40+
});
41+
}).toThrowDeveloperError();
42+
});
43+
3544
it("throws when creating a sampler with invalid wrapS", function () {
3645
expect(function () {
3746
return new Sampler({

0 commit comments

Comments
 (0)