mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 13:59:30 -07:00
Refactoring the pass and pipeline, so that inputs and size are handed to and returned from the build function (formerly setSize). This is now the earliest place to build bind groups, which makes sense, because it's also the earliest place to create textures that are proportional to the size of the canvas.
This commit is contained in:
@@ -2,7 +2,7 @@ import { loadShader, makeBindGroup, makePass } from "./utils.js";
|
||||
|
||||
const numVerticesPerQuad = 2 * 3;
|
||||
|
||||
export default (context, getInputs) => {
|
||||
export default (context) => {
|
||||
const { config, device, canvasFormat, canvasContext } = context;
|
||||
|
||||
const linearSampler = device.createSampler({
|
||||
@@ -21,10 +21,11 @@ export default (context, getInputs) => {
|
||||
};
|
||||
|
||||
let renderPipeline;
|
||||
let renderBindGroup;
|
||||
|
||||
const assets = [loadShader(device, "shaders/wgsl/endPass.wgsl")];
|
||||
|
||||
const ready = (async () => {
|
||||
const loaded = (async () => {
|
||||
const [imageShader] = await Promise.all(assets);
|
||||
|
||||
renderPipeline = device.createRenderPipeline({
|
||||
@@ -44,10 +45,12 @@ export default (context, getInputs) => {
|
||||
});
|
||||
})();
|
||||
|
||||
const execute = (encoder) => {
|
||||
const inputs = getInputs();
|
||||
const tex = inputs.primary;
|
||||
const renderBindGroup = makeBindGroup(device, renderPipeline, 0, [linearSampler, tex.createView()]);
|
||||
const build = (size, inputs) => {
|
||||
renderBindGroup = makeBindGroup(device, renderPipeline, 0, [linearSampler, inputs.primary.createView()]);
|
||||
return null;
|
||||
};
|
||||
|
||||
const run = (encoder) => {
|
||||
renderPassConfig.colorAttachments[0].view = canvasContext.getCurrentTexture().createView();
|
||||
const renderPass = encoder.beginRenderPass(renderPassConfig);
|
||||
renderPass.setPipeline(renderPipeline);
|
||||
@@ -56,5 +59,5 @@ export default (context, getInputs) => {
|
||||
renderPass.endPass();
|
||||
};
|
||||
|
||||
return makePass(null, ready, null, execute);
|
||||
return makePass(loaded, build, run);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user