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

Small cleanup to the way antialiasing set up is handled #5679

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/platform/graphics/graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class GraphicsDevice extends EventHandler {
*/
backBufferFormat;

/**
* True if the back buffer should use anti-aliasing.
*/
backBufferAntialias = false;

/**
* True if the deviceType is WebGPU
*
Expand Down
14 changes: 9 additions & 5 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
let gl = null;

// we always allocate the default framebuffer without antialiasing, so remove that option
const antialias = options.antialias;
this.backBufferAntialias = options.antialias ?? false;
options.antialias = false;

// Retrieve the WebGL context
Expand Down Expand Up @@ -406,8 +406,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
this.initializeRenderState();
this.initializeContextCaches();

// handle anti-aliasing internally
this.samples = this.isWebGL2 && antialias ? 4 : 1;
this.createBackbuffer(null);

// only enable ImageBitmap on chrome
Expand Down Expand Up @@ -1033,8 +1031,14 @@ class WebglGraphicsDevice extends GraphicsDevice {
ext = this.extTextureFilterAnisotropic;
this.maxAnisotropy = ext ? gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;

this.samples = gl.getParameter(gl.SAMPLES);
this.maxSamples = this.isWebGL2 && !this.forceDisableMultisampling ? gl.getParameter(gl.MAX_SAMPLES) : 1;
const antialiasSupported = this.isWebGL2 && !this.forceDisableMultisampling;
this.maxSamples = antialiasSupported ? gl.getParameter(gl.MAX_SAMPLES) : 1;

// some devices incorrectly report max samples larger than 4
this.maxSamples = Math.min(this.maxSamples, 4);

// we handle anti-aliasing internally by allocating multi-sampled backbuffer
this.samples = antialiasSupported && this.backBufferAntialias ? this.maxSamples : 1;

// Don't allow area lights on old android devices, they often fail to compile the shader, run it incorrectly or are very slow.
this.supportsAreaLights = this.isWebGL2 || !platform.android;
Expand Down
7 changes: 4 additions & 3 deletions src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
super(canvas, options);
options = this.initOptions;

this.backBufferAntialias = options.antialias ?? false;
this.isWebGPU = true;
this._deviceType = DEVICETYPE_WEBGPU;

// WebGPU currently only supports 1 and 4 samples
this.samples = options.antialias ? 4 : 1;

this.setupPassEncoderDefaults();
}

Expand Down Expand Up @@ -151,6 +149,9 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
this.extBlendMinmax = true;
this.areaLightLutFormat = this.floatFilterable ? PIXELFORMAT_RGBA32F : PIXELFORMAT_RGBA8;
this.supportsTextureFetch = true;

// WebGPU currently only supports 1 and 4 samples
this.samples = this.backBufferAntialias ? 4 : 1;
}

async initWebGpu(glslangUrl, twgslUrl) {
Expand Down