Skip to content

Commit

Permalink
Merge pull request #112 from Absulit/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Absulit authored May 26, 2024
2 parents 372d76c + 0f09dac commit 73e960f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions examples/circleblur/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import vert from './vert.js';
import compute from './compute.js';
import frag from './frag.js';
import RenderPass from 'renderpass';
import Points from 'points';
const circleblur = {
renderPasses: [
new RenderPass(null, null, compute, 800, 800, 1),
new RenderPass(vert, frag, null, 8, 1, 1)
],
/**
*
* @param {Points} points
*/
init: async points => {
points.addSampler('feedbackSampler', null);
points.addTexture2d('feedbackTexture', true);
Expand Down
13 changes: 7 additions & 6 deletions examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ document.addEventListener('fullscreenchange', e => {
fullscreenCheck.updateDisplay();
});

let isFitWindow = (localStorage.getItem('fitwindow-enabled') === 'true') || false;
let isFitWindowData = { 'isFitWindow': isFitWindow };
gui.add(isFitWindowData, 'isFitWindow').name('Fit Window').onChange(value => {
let isFitWindowData = { 'isFitWindow': false };
gui.add(isFitWindowData, 'isFitWindow').name('Fit Window').listen().onChange(value => {
points.fitWindow = value;
localStorage.setItem('fitwindow-enabled', value);
});

const shaderProjects = [
Expand Down Expand Up @@ -170,8 +168,11 @@ async function init() {
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
}

const canvas = document.getElementById('gl-canvas');
canvas.width = 800;
canvas.height = 800;
points = new Points('gl-canvas');
isFitWindowData.isFitWindow = false;

gui.removeFolder(optionsFolder);
optionsFolder = gui.addFolder(FOLDER_NAME);
Expand All @@ -182,7 +183,7 @@ async function init() {
await points.init(renderPasses);

let hasVertexAndFragmentShader = renderPasses.every(renderPass => renderPass.hasVertexAndFragmentShader)
hasVertexAndFragmentShader && (points.fitWindow = isFitWindow);
hasVertexAndFragmentShader;

update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/videotexture1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

const options = {
scale: .180,
scale: 1,
}

import vert from './vert.js';
Expand Down
24 changes: 19 additions & 5 deletions src/absulit.points.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ export default class Points {
format: 'depth24plus',
usage: GPUTextureUsage.RENDER_ATTACHMENT,
});

// this is to solve an issue that requires the texture to be resized
// if the screen dimensions change, this for a `addTexture2d` with
// `copyCurrentTexture` parameter set to `true`.
this._textures2d.forEach(texture2d => {
if (!texture2d.imageTexture && texture2d.texture) {
this._createTextureBindingToCopy(texture2d);
}
})
}

/** @private */
Expand Down Expand Up @@ -1023,11 +1032,7 @@ export default class Points {

texture2d.texture = cubeTexture;
} else {
texture2d.texture = this._device.createTexture({
size: this._presentationSize,
format: this._presentationFormat, // if 'depth24plus' throws error
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
});
this._createTextureBindingToCopy(texture2d);
}
});
//--------------------------------------------
Expand All @@ -1046,6 +1051,15 @@ export default class Points {
});
}

/** @private */
_createTextureBindingToCopy(texture2d){
texture2d.texture = this._device.createTexture({
size: this._presentationSize,
format: this._presentationFormat, // if 'depth24plus' throws error
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
});
}

/** @private */
_createComputeBindGroup() {
this._renderPasses.forEach((renderPass, index) => {
Expand Down

0 comments on commit 73e960f

Please sign in to comment.