pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
53 lines (50 loc) • 1.72 kB
JavaScript
import { ExtensionType } from '../../../extensions/Extensions.mjs';
import { State } from '../../renderers/shared/state/State.mjs';
;
class GlBatchAdaptor {
constructor() {
this._tempState = State.for2d();
/**
* We only want to sync the a batched shaders uniforms once on first use
* this is a hash of shader uids to a boolean value. When the shader is first bound
* we set the value to true. When the shader is bound again we check the value and
* if it is true we know that the uniforms have already been synced and we skip it.
*/
this._didUploadHash = {};
}
init(batcherPipe) {
batcherPipe.renderer.runners.contextChange.add(this);
}
contextChange() {
this._didUploadHash = {};
}
start(batchPipe, geometry, shader) {
const renderer = batchPipe.renderer;
const didUpload = this._didUploadHash[shader.uid];
renderer.shader.bind(shader, didUpload);
if (!didUpload) {
this._didUploadHash[shader.uid] = true;
}
renderer.shader.updateUniformGroup(renderer.globalUniforms.uniformGroup);
renderer.geometry.bind(geometry, shader.glProgram);
}
execute(batchPipe, batch) {
const renderer = batchPipe.renderer;
this._tempState.blendMode = batch.blendMode;
renderer.state.set(this._tempState);
const textures = batch.textures.textures;
for (let i = 0; i < batch.textures.count; i++) {
renderer.texture.bind(textures[i], i);
}
renderer.geometry.draw(batch.topology, batch.size, batch.start);
}
}
/** @ignore */
GlBatchAdaptor.extension = {
type: [
ExtensionType.WebGLPipesAdaptor
],
name: "batch"
};
export { GlBatchAdaptor };
//# sourceMappingURL=GlBatchAdaptor.mjs.map