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

Removed few remaining .isWebGL2 tests that are now true #6873

Merged
merged 1 commit into from
Aug 2, 2024
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
2 changes: 1 addition & 1 deletion src/platform/graphics/webgl/webgl-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WebglBuffer {
glUsage = gl.STREAM_DRAW;
break;
case BUFFER_GPUDYNAMIC:
glUsage = device.isWebGL2 ? gl.DYNAMIC_COPY : gl.STATIC_DRAW;
glUsage = gl.DYNAMIC_COPY;
break;
}

Expand Down
54 changes: 25 additions & 29 deletions src/platform/graphics/webgl/webgl-render-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class WebglRenderTarget {
} else if (target._depth) {
// --- Init a new depth/stencil buffer (optional) ---
// if device is a MSAA RT, and no buffer to resolve to, skip creating non-MSAA depth
const willRenderMsaa = target._samples > 1 && device.isWebGL2;
const willRenderMsaa = target._samples > 1;
if (!willRenderMsaa) {
if (!this._glDepthBuffer) {
this._glDepthBuffer = gl.createRenderbuffer();
Expand All @@ -198,8 +198,7 @@ class WebglRenderTarget {
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, target.width, target.height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this._glDepthBuffer);
} else {
const depthFormat = device.isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT16;
gl.renderbufferStorage(gl.RENDERBUFFER, depthFormat, target.width, target.height);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT32F, target.width, target.height);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this._glDepthBuffer);
}
gl.bindRenderbuffer(gl.RENDERBUFFER, null);
Expand All @@ -209,8 +208,8 @@ class WebglRenderTarget {
Debug.call(() => this._checkFbo(device, target));
}

// ##### Create MSAA FBO (WebGL2 only) #####
if (device.isWebGL2 && target._samples > 1) {
// ##### Create MSAA FBO #####
if (target._samples > 1) {

Debug.call(() => {
if (target.width <= 0 || target.height <= 0) {
Expand Down Expand Up @@ -376,40 +375,37 @@ class WebglRenderTarget {
}

resolve(device, target, color, depth) {
if (device.isWebGL2) {

const gl = device.gl;

// if MRT is used, we need to resolve each buffer individually
if (this.colorMrtFramebuffers) {
const gl = device.gl;

// color
if (color) {
for (let i = 0; i < this.colorMrtFramebuffers.length; i++) {
const fbPair = this.colorMrtFramebuffers[i];
// if MRT is used, we need to resolve each buffer individually
if (this.colorMrtFramebuffers) {

DebugGraphics.pushGpuMarker(device, `RESOLVE-MRT${i}`);
this.internalResolve(device, fbPair.msaaFB, fbPair.resolveFB, target, gl.COLOR_BUFFER_BIT);
DebugGraphics.popGpuMarker(device);
}
}
// color
if (color) {
for (let i = 0; i < this.colorMrtFramebuffers.length; i++) {
const fbPair = this.colorMrtFramebuffers[i];

// depth
if (depth) {
DebugGraphics.pushGpuMarker(device, `RESOLVE-MRT-DEPTH`);
this.internalResolve(device, this._glFrameBuffer, this._glResolveFrameBuffer, target, gl.DEPTH_BUFFER_BIT);
DebugGraphics.pushGpuMarker(device, `RESOLVE-MRT${i}`);
this.internalResolve(device, fbPair.msaaFB, fbPair.resolveFB, target, gl.COLOR_BUFFER_BIT);
DebugGraphics.popGpuMarker(device);
}
}

} else {
DebugGraphics.pushGpuMarker(device, `RESOLVE`);
this.internalResolve(device, this._glFrameBuffer, this._glResolveFrameBuffer, target,
(color ? gl.COLOR_BUFFER_BIT : 0) | (depth ? gl.DEPTH_BUFFER_BIT : 0));
// depth
if (depth) {
DebugGraphics.pushGpuMarker(device, `RESOLVE-MRT-DEPTH`);
this.internalResolve(device, this._glFrameBuffer, this._glResolveFrameBuffer, target, gl.DEPTH_BUFFER_BIT);
DebugGraphics.popGpuMarker(device);
}

gl.bindFramebuffer(gl.FRAMEBUFFER, this._glFrameBuffer);
} else {
DebugGraphics.pushGpuMarker(device, `RESOLVE`);
this.internalResolve(device, this._glFrameBuffer, this._glResolveFrameBuffer, target,
(color ? gl.COLOR_BUFFER_BIT : 0) | (depth ? gl.DEPTH_BUFFER_BIT : 0));
DebugGraphics.popGpuMarker(device);
}

gl.bindFramebuffer(gl.FRAMEBUFFER, this._glFrameBuffer);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/scene/graphics/render-pass-color-grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ class RenderPassColorGrab extends RenderPass {
allocateRenderTarget(renderTarget, sourceRenderTarget, device, format) {

// allocate texture buffer
const mipmaps = device.isWebGL2;
const texture = new Texture(device, {
name: _colorUniformName,
format,
width: sourceRenderTarget ? sourceRenderTarget.colorBuffer.width : device.width,
height: sourceRenderTarget ? sourceRenderTarget.colorBuffer.height : device.height,
mipmaps,
minFilter: mipmaps ? FILTER_LINEAR_MIPMAP_LINEAR : FILTER_LINEAR,
mipmaps: true,
minFilter: FILTER_LINEAR_MIPMAP_LINEAR,
magFilter: FILTER_LINEAR,
addressU: ADDRESS_CLAMP_TO_EDGE,
addressV: ADDRESS_CLAMP_TO_EDGE
Expand Down Expand Up @@ -122,7 +121,7 @@ class RenderPassColorGrab extends RenderPass {
// generate mipmaps
device.mipmapRenderer.generate(this.colorRenderTarget.colorBuffer.impl);

} else if (device.isWebGL2) {
} else {

device.copyRenderTarget(sourceRt, this.colorRenderTarget, true, false);

Expand Down
17 changes: 7 additions & 10 deletions src/scene/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,16 +886,13 @@ class Light {
}

_updateShadowBias() {
const device = this.device;
if (device.isWebGL2 || device.isWebGPU) {
if (this._type === LIGHTTYPE_OMNI && !this.clusteredLighting) {
this.shadowDepthState.depthBias = 0;
this.shadowDepthState.depthBiasSlope = 0;
} else {
const bias = this.shadowBias * -1000.0;
this.shadowDepthState.depthBias = bias;
this.shadowDepthState.depthBiasSlope = bias;
}
if (this._type === LIGHTTYPE_OMNI && !this.clusteredLighting) {
this.shadowDepthState.depthBias = 0;
this.shadowDepthState.depthBiasSlope = 0;
} else {
const bias = this.shadowBias * -1000.0;
this.shadowDepthState.depthBias = bias;
this.shadowDepthState.depthBiasSlope = bias;
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/scene/renderer/shadow-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ class ShadowRenderer {

// Set standard shadowmap states
const isClustered = this.renderer.scene.clusteredLightingEnabled;
const gpuOrGl2 = device.isWebGL2 || device.isWebGPU;
const useShadowSampler = isClustered ?
light._isPcf && gpuOrGl2 : // both spot and omni light are using shadow sampler on webgl2 when clustered
light._isPcf && gpuOrGl2 && light._type !== LIGHTTYPE_OMNI; // for non-clustered, point light is using depth encoded in color buffer (should change to shadow sampler)
light._isPcf : // both spot and omni light are using shadow sampler when clustered
light._isPcf && light._type !== LIGHTTYPE_OMNI; // for non-clustered, point light is using depth encoded in color buffer (should change to shadow sampler)

device.setBlendState(useShadowSampler ? this.blendStateNoWrite : this.blendStateWrite);
device.setDepthState(light.shadowDepthState);
Expand Down
2 changes: 1 addition & 1 deletion src/scene/shader-lib/programs/lit-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ class LitShader {
if (lightType === LIGHTTYPE_DIRECTIONAL) {
func.append("#define SHADOW_SAMPLE_ORTHO");
}
if ((pcfShadows || pcssShadows) && device.isWebGL2 || device.isWebGPU) {
if ((pcfShadows || pcssShadows) || device.isWebGPU) {
func.append("#define SHADOW_SAMPLE_SOURCE_ZBUFFER");
}
if (lightType === LIGHTTYPE_OMNI) {
Expand Down