Skip to content

Commit

Permalink
Merge pull request #321 from Codas/fix-batch-shader-initialization-again
Browse files Browse the repository at this point in the history
Fix batch shader initialization.
  • Loading branch information
Haxxer authored Sep 29, 2024
2 parents 12b4e05 + f18cc85 commit 757f0f1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
77 changes: 77 additions & 0 deletions src/lib/filters/vision-mask-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,81 @@ export default class VisionSamplerShader extends BaseSamplerShader {
uint16View[k++] = textureId;
}
}

// need to override createPlugin as canvas.performance is not defined in foundry when
// we need it to be
static createPlugin() {
const shaderClass = this;
const geometryClass = Array.isArray(shaderClass.batchGeometry)
? class BatchGeometry extends PIXI.Geometry {
constructor(_static=false) {
super();
this._buffer = new PIXI.Buffer(null, _static, false);
this._indexBuffer = new PIXI.Buffer(null, _static, true);
for ( const {id, size, normalized, type} of shaderClass.batchGeometry ) {
this.addAttribute(id, this._buffer, size, normalized, type);
}
this.addIndex(this._indexBuffer);
}
} : shaderClass.batchGeometry;
return class BatchPlugin extends shaderClass.batchRendererClass {

/** @override */
static get shaderGeneratorClass() {
return shaderClass.batchShaderGeneratorClass;
}

/* ---------------------------------------- */

/** @override */
static get defaultVertexSrc() {
return shaderClass.batchVertexShader;
}

/* ---------------------------------------- */

/** @override */
static get defaultFragmentTemplate() {
return shaderClass.batchFragmentShader;
}

/* ---------------------------------------- */

/** @override */
static get defaultUniforms() {
return shaderClass.batchDefaultUniforms;
}

/* ---------------------------------------- */

/**
* The batch plugin constructor.
* @param {PIXI.Renderer} renderer The renderer
*/
constructor(renderer) {
super(renderer);
this.geometryClass = geometryClass;
this.vertexSize = shaderClass.batchVertexSize;
this.reservedTextureUnits = shaderClass.reservedTextureUnits;
this._packInterleavedGeometry = shaderClass._packInterleavedGeometry;
this._preRenderBatch = shaderClass._preRenderBatch;
}

/* ---------------------------------------- */

/** @inheritdoc */
setShaderGenerator(options) {
// if ( !canvas.performance ) return;
super.setShaderGenerator(options);
}

/* ---------------------------------------- */

/** @inheritdoc */
contextChange() {
this.shaderGenerator = null;
super.contextChange();
}
};
}
}
7 changes: 2 additions & 5 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,12 @@ function initializeModule() {
registerLayers();
registerHotkeys();
registerLibwrappers();
registerBatchShader();

SequencerAboveUILayer.setup();
SequencerEffectManager.setup();
SequencerAboveUILayer.setup();
}

Hooks.once('canvasConfig', () => {
registerBatchShader();
})

Hooks.once("ready", async () => {

if(!game.user.isGM || game.settings.get(CONSTANTS.MODULE_NAME, "welcome-shown")) return;
Expand Down

0 comments on commit 757f0f1

Please sign in to comment.