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
import BoundingRectangle from "../Core/BoundingRectangle.js";
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import PixelFormat from "../Core/PixelFormat.js";
import Framebuffer from "../Renderer/Framebuffer.js";
import PixelDatatype from "../Renderer/PixelDatatype.js";
import RenderState from "../Renderer/RenderState.js";
import Sampler from "../Renderer/Sampler.js";
import Texture from "../Renderer/Texture.js";
import BrdfLutGeneratorFS from "../Shaders/BrdfLutGeneratorFS.js";
/**
* @private
*/
function BrdfLutGenerator() {
this._framebuffer = undefined;
this._colorTexture = undefined;
this._drawCommand = undefined;
}
Object.defineProperties(BrdfLutGenerator.prototype, {
colorTexture: {
get: function () {
return this._colorTexture;
},
},
});
function createCommand(generator, context) {
var framebuffer = generator._framebuffer;
var drawCommand = context.createViewportQuadCommand(BrdfLutGeneratorFS, {
framebuffer: framebuffer,
renderState: RenderState.fromCache({
viewport: new BoundingRectangle(0.0, 0.0, 256.0, 256.0),
}),
});
generator._drawCommand = drawCommand;
}
function createFramebuffer(generator, context) {
var colorTexture = new Texture({
context: context,
width: 256,
height: 256,
pixelFormat: PixelFormat.RGBA,
pixelDatatype: PixelDatatype.UNSIGNED_BYTE,
sampler: Sampler.NEAREST,
});
generator._colorTexture = colorTexture;
var framebuffer = new Framebuffer({
context: context,
colorTextures: [colorTexture],
destroyAttachments: false,
});
generator._framebuffer = framebuffer;
}
BrdfLutGenerator.prototype.update = function (frameState) {
if (!defined(this._colorTexture)) {
var context = frameState.context;
createFramebuffer(this, context);
createCommand(this, context);
this._drawCommand.execute(context);
this._framebuffer = this._framebuffer && this._framebuffer.destroy();
this._drawCommand.shaderProgram =
this._drawCommand.shaderProgram &&
this._drawCommand.shaderProgram.destroy();
}
};
BrdfLutGenerator.prototype.isDestroyed = function () {
return false;
};
BrdfLutGenerator.prototype.destroy = function () {
this._colorTexture = this._colorTexture && this._colorTexture.destroy();
return destroyObject(this);
};
export default BrdfLutGenerator;