Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom target for readPixels #16347

Merged
merged 20 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1a5c0ec
move timer stats to thinEngine
sebavan Jan 31, 2025
ac8a4df
fix case
sebavan Jan 31, 2025
be5fee1
PR Feedback
sebavan Jan 31, 2025
28ee546
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Feb 3, 2025
95c5e9c
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Feb 4, 2025
87862a8
Add Irradiance texture support in Env format
sebavan Feb 5, 2025
f2df95f
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Feb 7, 2025
bcda538
Fix HDR irradiance filtering not rendering if scene not rendering yet
sebavan Feb 7, 2025
d6d27af
pr feedback
sebavan Feb 7, 2025
f7bbc55
Fix PR feedback... or mostly the PR thanks @bghgary
sebavan Feb 7, 2025
6fdb987
fix test
sebavan Feb 7, 2025
f02a292
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Feb 17, 2025
7e8f100
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Feb 27, 2025
8eb7842
Fix is32Bits detection in geometry
sebavan Feb 27, 2025
3babde0
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Mar 4, 2025
96351e0
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Mar 6, 2025
cdfc7a1
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Mar 10, 2025
ee7650b
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Mar 11, 2025
4335afe
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan Mar 18, 2025
4e460c4
Allow custom target for readPixels
sebavan Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4497,12 +4497,21 @@ export class ThinEngine extends AbstractEngine {
* @param height defines the height of the rectangle where pixels must be read
* @param hasAlpha defines whether the output should have alpha or not (defaults to true)
* @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
* @param data defines the data to fill with the read pixels (if not provided, a new one will be created)
* @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
*/
public readPixels(x: number, y: number, width: number, height: number, hasAlpha = true, flushRenderer = true): Promise<ArrayBufferView> {
public readPixels(x: number, y: number, width: number, height: number, hasAlpha = true, flushRenderer = true, data: Nullable<Uint8Array> = null): Promise<ArrayBufferView> {
const numChannels = hasAlpha ? 4 : 3;
const format = hasAlpha ? this._gl.RGBA : this._gl.RGB;
const data = new Uint8Array(height * width * numChannels);

const dataLength = width * height * numChannels;
if (!data) {
data = new Uint8Array(dataLength);
} else if (data.length < dataLength) {
Logger.Error(`Data buffer is too small to store the read pixels (${data.length} should be more than ${dataLength})`);
return Promise.resolve(data);
}

if (flushRenderer) {
this.flushFramebuffer();
}
Expand Down
5 changes: 3 additions & 2 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,10 +2899,11 @@ export class WebGPUEngine extends ThinWebGPUEngine {
* @param height defines the height of the rectangle where pixels must be read
* @param hasAlpha defines whether the output should have alpha or not (defaults to true)
* @param flushRenderer true to flush the renderer from the pending commands before reading the pixels
* @param data defines the data to fill with the read pixels (if not provided, a new one will be created)
* @returns a ArrayBufferView promise (Uint8Array) containing RGBA colors
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public readPixels(x: number, y: number, width: number, height: number, hasAlpha = true, flushRenderer = true): Promise<ArrayBufferView> {
public readPixels(x: number, y: number, width: number, height: number, hasAlpha = true, flushRenderer = true, data: Nullable<Uint8Array> = null): Promise<ArrayBufferView> {
const renderPassWrapper = this._getCurrentRenderPassWrapper();
const hardwareTexture = renderPassWrapper.colorAttachmentGPUTextures[0];
if (!hardwareTexture) {
Expand All @@ -2918,7 +2919,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
if (flushRenderer) {
this.flushFramebuffer();
}
return this._textureHelper.readPixels(gpuTexture, x, y, width, height, gpuTextureFormat);
return this._textureHelper.readPixels(gpuTexture, x, y, width, height, gpuTextureFormat, undefined, undefined, data);
}

//------------------------------------------------------------------------------
Expand Down
Loading