Skip to content
Merged
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions src/platform/graphics/webgl/webgl-render-target.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Debug } from '../../../core/debug.js';
import { PIXELFORMAT_RGBA8 } from '../constants.js';
import { DebugGraphics } from '../debug-graphics.js';
import { DeviceCache } from '../device-cache.js';
import { getMultisampledTextureCache } from '../multi-sampled-texture-cache.js';

/**
* @import { RenderTarget } from '../render-target.js'
* @import { WebglGraphicsDevice } from './webgl-graphics-device.js'
*/

const _validatedFboConfigs = new DeviceCache();

/**
* A private class representing a pair of framebuffers, when MSAA is used.
*
Expand Down Expand Up @@ -372,6 +375,24 @@ class WebglRenderTarget {
* @private
*/
_checkFbo(device, target, type = '') {

// Build a key from attachment formats, depth/stencil config, samples, and FBO type.
// Dimensions are excluded as they don't affect framebuffer completeness.
const colorFormats = target._colorBuffers?.map(b => b?.format ?? -1).join(',') ?? '';
const depthInfo = target._depth ? (target._depthBuffer ? `dt${target._depthBuffer.format}` : (target._stencil ? 'ds' : 'd')) : '';
const key = `${type}:${colorFormats}:${depthInfo}:${target._samples}`;

// clear validated configs on context loss to re-validate after restore
const validated = _validatedFboConfigs.get(device, () => {
const set = new Set();
set.loseContext = () => set.clear();
return set;
});

if (validated.has(key)) {
return;
}

const gl = device.gl;
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
let errorCode;
Expand All @@ -390,6 +411,10 @@ class WebglRenderTarget {
break;
}

if (!errorCode) {
validated.add(key);
}

Debug.assert(!errorCode, `Framebuffer creation failed with error code ${errorCode}, render target: ${target.name} ${type}`, target);
}

Expand Down