Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | 16676x 16676x 16676x 16676x 16676x 16676x 16676x 16676x 1x 16675x 1x 16674x 16674x 16674x 16674x 16674x 16674x 16674x 16674x 16674x 16674x 15308x 15308x 16674x 16674x 16674x 16674x 16674x 16674x 1x 13806x 13806x 1x 1x 710x 710x 710x 710x 710x 710x 1x 713x 3x 710x 710x 710x 710x 193x 193x 193x 193x 193x 193x 193x 193x 189x 209x 207x 191x 75x 75x 191x 5x 5x 191x 191x 1x 105x 105x 1x 104x 1x 7x 7x 1x 6x 1x 5x 5x 1x 1x 1x 8x 1x 3x 1x 2x 2x 1x 4x 1x 2x 1x 1x 1x 1x 4x 1x 2x 1x 1x 1x 1x 69x 1x 2x 1x 1x 1x 1x 13x 1x 144x 144x 144x 144x 1x 13838x 13838x 1x 13837x 12491x 12491x 12491x 15225x 15225x 15214x 194x 15225x 197x 15225x 15225x 15214x 15225x 13837x 8141x 8141x 8141x 8141x 8141x 13837x 11x 11x 11x 11x 11x 13837x | import Framebuffer from "./Framebuffer.js";
import MultisampleFramebuffer from "./MultisampleFramebuffer.js";
import PixelDatatype from "./PixelDatatype.js";
import Renderbuffer from "./Renderbuffer.js";
import RenderbufferFormat from "./RenderbufferFormat.js";
import Sampler from "./Sampler.js";
import Texture from "./Texture.js";
import Frozen from "../Core/Frozen.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import PixelFormat from "../Core/PixelFormat.js";
/**
* Creates a wrapper object around a framebuffer and its resources.
*
* @param {object} options Object with the following properties:
* @param {number} [options.numSamples=1] The multisampling rate of the render targets. Requires a WebGL2 context.
* @param {number} [options.colorAttachmentsLength=1] The number of color attachments this FramebufferManager will create.
* @param {boolean} [options.color=true] Whether the FramebufferManager will use color attachments.
* @param {boolean} [options.depth=false] Whether the FramebufferManager will use depth attachments.
* @param {boolean} [options.depthStencil=false] Whether the FramebufferManager will use depth-stencil attachments.
* @param {boolean} [options.supportsDepthTexture=false] Whether the FramebufferManager will create a depth texture when the extension is supported.
* @param {boolean} [options.createColorAttachments=true] Whether the FramebufferManager will construct its own color attachments.
* @param {boolean} [options.createDepthAttachments=true] Whether the FramebufferManager will construct its own depth attachments.
* @param {PixelDatatype} [options.pixelDatatype=undefined] The default pixel datatype to use when creating color attachments.
* @param {PixelFormat} [options.pixelFormat=undefined] The default pixel format to use when creating color attachments.
*
* @exception {DeveloperError} Must enable at least one type of framebuffer attachment.
* @exception {DeveloperError} Cannot have both a depth and depth-stencil attachment.
*
* @private
* @constructor
*/
function FramebufferManager(options) {
options = options ?? Frozen.EMPTY_OBJECT;
this._numSamples = options.numSamples ?? 1;
this._colorAttachmentsLength = options.colorAttachmentsLength ?? 1;
this._color = options.color ?? true;
this._depth = options.depth ?? false;
this._depthStencil = options.depthStencil ?? false;
this._supportsDepthTexture = options.supportsDepthTexture ?? false;
//>>includeStart('debug', pragmas.debug);
if (!this._color && !this._depth && !this._depthStencil) {
throw new DeveloperError(
"Must enable at least one type of framebuffer attachment.",
);
}
if (this._depth && this._depthStencil) {
throw new DeveloperError(
"Cannot have both a depth and depth-stencil attachment.",
);
}
//>>includeEnd('debug');
this._createColorAttachments = options.createColorAttachments ?? true;
this._createDepthAttachments = options.createDepthAttachments ?? true;
this._pixelDatatype = options.pixelDatatype;
this._pixelFormat = options.pixelFormat;
this._width = undefined;
this._height = undefined;
this._framebuffer = undefined;
this._multisampleFramebuffer = undefined;
this._colorTextures = undefined;
if (this._color) {
this._colorTextures = new Array(this._colorAttachmentsLength);
this._colorRenderbuffers = new Array(this._colorAttachmentsLength);
}
this._colorRenderbuffer = undefined;
this._depthStencilRenderbuffer = undefined;
this._depthStencilTexture = undefined;
this._depthRenderbuffer = undefined;
this._depthTexture = undefined;
this._attachmentsDirty = false;
}
Object.defineProperties(FramebufferManager.prototype, {
framebuffer: {
get: function () {
Iif (this._numSamples > 1) {
return this._multisampleFramebuffer.getRenderFramebuffer();
}
return this._framebuffer;
},
},
numSamples: {
get: function () {
return this._numSamples;
},
},
status: {
get: function () {
return this.framebuffer.status;
},
},
});
FramebufferManager.prototype.isDirty = function (
width,
height,
numSamples,
pixelDatatype,
pixelFormat,
) {
numSamples = numSamples ?? 1;
const dimensionChanged = this._width !== width || this._height !== height;
const samplesChanged = this._numSamples !== numSamples;
const pixelChanged =
(defined(pixelDatatype) && this._pixelDatatype !== pixelDatatype) ||
(defined(pixelFormat) && this._pixelFormat !== pixelFormat);
const framebufferDefined =
numSamples === 1
? defined(this._framebuffer)
: defined(this._multisampleFramebuffer);
return (
this._attachmentsDirty ||
dimensionChanged ||
samplesChanged ||
pixelChanged ||
!framebufferDefined ||
(this._color && !defined(this._colorTextures[0]))
);
};
FramebufferManager.prototype.update = function (
context,
width,
height,
numSamples,
pixelDatatype,
pixelFormat,
) {
//>>includeStart('debug', pragmas.debug);
if (!defined(width) || !defined(height)) {
throw new DeveloperError("width and height must be defined.");
}
//>>includeEnd('debug');
numSamples = context.msaa ? (numSamples ?? 1) : 1;
pixelDatatype =
pixelDatatype ??
(this._color
? (this._pixelDatatype ?? PixelDatatype.UNSIGNED_BYTE)
: undefined);
pixelFormat =
pixelFormat ??
(this._color ? (this._pixelFormat ?? PixelFormat.RGBA) : undefined);
if (this.isDirty(width, height, numSamples, pixelDatatype, pixelFormat)) {
this.destroy();
this._width = width;
this._height = height;
this._numSamples = numSamples;
this._pixelDatatype = pixelDatatype;
this._pixelFormat = pixelFormat;
this._attachmentsDirty = false;
// Create color texture
if (this._color && this._createColorAttachments) {
for (let i = 0; i < this._colorAttachmentsLength; ++i) {
this._colorTextures[i] = new Texture({
context: context,
width: width,
height: height,
pixelFormat: pixelFormat,
pixelDatatype: pixelDatatype,
sampler: Sampler.NEAREST,
});
Iif (this._numSamples > 1) {
const format = RenderbufferFormat.getColorFormat(pixelDatatype);
this._colorRenderbuffers[i] = new Renderbuffer({
context: context,
width: width,
height: height,
format: format,
numSamples: this._numSamples,
});
}
}
}
// Create depth stencil texture or renderbuffer
if (this._depthStencil && this._createDepthAttachments) {
Iif (this._supportsDepthTexture && context.depthTexture) {
this._depthStencilTexture = new Texture({
context: context,
width: width,
height: height,
pixelFormat: PixelFormat.DEPTH_STENCIL,
pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,
sampler: Sampler.NEAREST,
});
if (this._numSamples > 1) {
this._depthStencilRenderbuffer = new Renderbuffer({
context: context,
width: width,
height: height,
format: RenderbufferFormat.DEPTH24_STENCIL8,
numSamples: this._numSamples,
});
}
} else {
this._depthStencilRenderbuffer = new Renderbuffer({
context: context,
width: width,
height: height,
format: RenderbufferFormat.DEPTH_STENCIL,
});
}
}
// Create depth texture
if (this._depth && this._createDepthAttachments) {
Iif (this._supportsDepthTexture && context.depthTexture) {
this._depthTexture = new Texture({
context: context,
width: width,
height: height,
pixelFormat: PixelFormat.DEPTH_COMPONENT,
pixelDatatype: PixelDatatype.UNSIGNED_INT,
sampler: Sampler.NEAREST,
});
} else {
this._depthRenderbuffer = new Renderbuffer({
context: context,
width: width,
height: height,
format: RenderbufferFormat.DEPTH_COMPONENT16,
});
}
}
Iif (this._numSamples > 1) {
this._multisampleFramebuffer = new MultisampleFramebuffer({
context: context,
width: this._width,
height: this._height,
colorTextures: this._colorTextures,
colorRenderbuffers: this._colorRenderbuffers,
depthStencilTexture: this._depthStencilTexture,
depthStencilRenderbuffer: this._depthStencilRenderbuffer,
destroyAttachments: false,
});
} else {
this._framebuffer = new Framebuffer({
context: context,
colorTextures: this._colorTextures,
depthTexture: this._depthTexture,
depthRenderbuffer: this._depthRenderbuffer,
depthStencilTexture: this._depthStencilTexture,
depthStencilRenderbuffer: this._depthStencilRenderbuffer,
destroyAttachments: false,
});
}
}
};
FramebufferManager.prototype.getColorTexture = function (index) {
index = index ?? 0;
//>>includeStart('debug', pragmas.debug);
if (index >= this._colorAttachmentsLength) {
throw new DeveloperError(
"index must be smaller than total number of color attachments.",
);
}
//>>includeEnd('debug');
return this._colorTextures[index];
};
FramebufferManager.prototype.setColorTexture = function (texture, index) {
index = index ?? 0;
//>>includeStart('debug', pragmas.debug);
if (this._createColorAttachments) {
throw new DeveloperError(
"createColorAttachments must be false if setColorTexture is called.",
);
}
if (index >= this._colorAttachmentsLength) {
throw new DeveloperError(
"index must be smaller than total number of color attachments.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = texture !== this._colorTextures[index];
this._colorTextures[index] = texture;
};
FramebufferManager.prototype.getColorRenderbuffer = function (index) {
index = index ?? 0;
//>>includeStart('debug', pragmas.debug);
if (index >= this._colorAttachmentsLength) {
throw new DeveloperError(
"index must be smaller than total number of color attachments.",
);
}
//>>includeEnd('debug');
return this._colorRenderbuffers[index];
};
FramebufferManager.prototype.setColorRenderbuffer = function (
renderbuffer,
index,
) {
index = index ?? 0;
//>>includeStart('debug', pragmas.debug);
if (this._createColorAttachments) {
throw new DeveloperError(
"createColorAttachments must be false if setColorRenderbuffer is called.",
);
}
if (index >= this._colorAttachmentsLength) {
throw new DeveloperError(
"index must be smaller than total number of color attachments.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = renderbuffer !== this._colorRenderbuffers[index];
this._colorRenderbuffers[index] = renderbuffer;
};
FramebufferManager.prototype.getDepthRenderbuffer = function () {
return this._depthRenderbuffer;
};
FramebufferManager.prototype.setDepthRenderbuffer = function (renderbuffer) {
//>>includeStart('debug', pragmas.debug);
if (this._createDepthAttachments) {
throw new DeveloperError(
"createDepthAttachments must be false if setDepthRenderbuffer is called.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = renderbuffer !== this._depthRenderbuffer;
this._depthRenderbuffer = renderbuffer;
};
FramebufferManager.prototype.getDepthTexture = function () {
return this._depthTexture;
};
FramebufferManager.prototype.setDepthTexture = function (texture) {
//>>includeStart('debug', pragmas.debug);
if (this._createDepthAttachments) {
throw new DeveloperError(
"createDepthAttachments must be false if setDepthTexture is called.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = texture !== this._depthTexture;
this._depthTexture = texture;
};
FramebufferManager.prototype.getDepthStencilRenderbuffer = function () {
return this._depthStencilRenderbuffer;
};
FramebufferManager.prototype.setDepthStencilRenderbuffer = function (
renderbuffer,
) {
//>>includeStart('debug', pragmas.debug);
if (this._createDepthAttachments) {
throw new DeveloperError(
"createDepthAttachments must be false if setDepthStencilRenderbuffer is called.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = renderbuffer !== this._depthStencilRenderbuffer;
this._depthStencilRenderbuffer = renderbuffer;
};
FramebufferManager.prototype.getDepthStencilTexture = function () {
return this._depthStencilTexture;
};
FramebufferManager.prototype.setDepthStencilTexture = function (texture) {
//>>includeStart('debug', pragmas.debug);
if (this._createDepthAttachments) {
throw new DeveloperError(
"createDepthAttachments must be false if setDepthStencilTexture is called.",
);
}
//>>includeEnd('debug');
this._attachmentsDirty = texture !== this._depthStencilTexture;
this._depthStencilTexture = texture;
};
/**
* If using MSAA, resolve the stencil.
*
* @param {Context} context
* @param {boolean} blitStencil
*
* @private
*/
FramebufferManager.prototype.prepareTextures = function (context, blitStencil) {
Iif (this._numSamples > 1) {
this._multisampleFramebuffer.blitFramebuffers(context, blitStencil);
}
};
FramebufferManager.prototype.clear = function (
context,
clearCommand,
passState,
) {
const framebuffer = clearCommand.framebuffer;
clearCommand.framebuffer = this.framebuffer;
clearCommand.execute(context, passState);
clearCommand.framebuffer = framebuffer;
};
FramebufferManager.prototype.destroyFramebuffer = function () {
this._framebuffer = this._framebuffer && this._framebuffer.destroy();
this._multisampleFramebuffer =
this._multisampleFramebuffer && this._multisampleFramebuffer.destroy();
};
FramebufferManager.prototype.destroy = function () {
if (this._color) {
const colorTextures = this._colorTextures;
const colorRenderbuffers = this._colorRenderbuffers;
for (let i = 0; i < colorTextures.length; ++i) {
const texture = colorTextures[i];
if (this._createColorAttachments) {
if (defined(texture) && !texture.isDestroyed()) {
texture.destroy();
}
}
if (defined(texture) && texture.isDestroyed()) {
colorTextures[i] = undefined;
}
const renderbuffer = colorRenderbuffers[i];
if (this._createColorAttachments) {
Iif (defined(renderbuffer) && !renderbuffer.isDestroyed()) {
renderbuffer.destroy();
}
}
Iif (defined(renderbuffer) && renderbuffer.isDestroyed()) {
colorRenderbuffers[i] = undefined;
}
}
}
if (this._depthStencil) {
Eif (this._createDepthAttachments) {
this._depthStencilTexture =
this._depthStencilTexture && this._depthStencilTexture.destroy();
this._depthStencilRenderbuffer =
this._depthStencilRenderbuffer &&
this._depthStencilRenderbuffer.destroy();
}
Iif (
defined(this._depthStencilTexture) &&
this._depthStencilTexture.isDestroyed()
) {
this._depthStencilTexture = undefined;
}
Iif (
defined(this._depthStencilRenderbuffer) &&
this._depthStencilRenderbuffer.isDestroyed()
) {
this._depthStencilRenderbuffer = undefined;
}
}
if (this._depth) {
Eif (this._createDepthAttachments) {
this._depthTexture = this._depthTexture && this._depthTexture.destroy();
this._depthRenderbuffer =
this._depthRenderbuffer && this._depthRenderbuffer.destroy();
}
Iif (defined(this._depthTexture) && this._depthTexture.isDestroyed()) {
this._depthTexture = undefined;
}
Iif (
defined(this._depthRenderbuffer) &&
this._depthRenderbuffer.isDestroyed()
) {
this._depthRenderbuffer = undefined;
}
}
this.destroyFramebuffer();
};
export default FramebufferManager;
|