95 lines
4.7 KiB
JavaScript
95 lines
4.7 KiB
JavaScript
shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$GraphicsPipe = function(global, require, module, exports) {
|
|
global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
|
|
var State = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$state$State"), GCManagedHash = require("module$node_modules$pixi_DOT_js$lib$utils$data$GCManagedHash"), PoolGroup = require("module$node_modules$pixi_DOT_js$lib$utils$pool$PoolGroup"), colorToUniform = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$gpu$colorToUniform"), BatchableGraphics = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$BatchableGraphics");
|
|
"use strict";
|
|
class GraphicsGpuData {
|
|
constructor() {
|
|
this.batches = [];
|
|
this.batched = !1;
|
|
}
|
|
destroy() {
|
|
this.batches.forEach(batch => {
|
|
PoolGroup.BigPool.return(batch);
|
|
});
|
|
this.batches.length = 0;
|
|
}
|
|
}
|
|
class GraphicsPipe {
|
|
constructor(renderer, adaptor) {
|
|
this.state = State.State.for2d();
|
|
this.renderer = renderer;
|
|
this._adaptor = adaptor;
|
|
this.renderer.runners.contextChange.add(this);
|
|
this._managedGraphics = new GCManagedHash.GCManagedHash({renderer, type:"renderable", priority:-1, name:"graphics"});
|
|
}
|
|
contextChange() {
|
|
this._adaptor.contextChange(this.renderer);
|
|
}
|
|
validateRenderable(graphics) {
|
|
const wasBatched = !!graphics._gpuData;
|
|
graphics = this.renderer.graphicsContext.updateGpuContext(graphics.context);
|
|
return graphics.isBatchable || wasBatched !== graphics.isBatchable ? !0 : !1;
|
|
}
|
|
addRenderable(graphics, instructionSet) {
|
|
const gpuContext = this.renderer.graphicsContext.updateGpuContext(graphics.context);
|
|
graphics.didViewUpdate && this._rebuild(graphics);
|
|
gpuContext.isBatchable ? this._addToBatcher(graphics, instructionSet) : (this.renderer.renderPipes.batch.break(instructionSet), instructionSet.add(graphics));
|
|
}
|
|
updateRenderable(graphics) {
|
|
graphics = this._getGpuDataForRenderable(graphics).batches;
|
|
for (let i = 0; i < graphics.length; i++) {
|
|
const batch = graphics[i];
|
|
batch._batcher.updateElement(batch);
|
|
}
|
|
}
|
|
execute(graphics) {
|
|
if (graphics.isRenderable) {
|
|
var renderer = this.renderer, context = graphics.context;
|
|
renderer.graphicsContext.getGpuContext(context).batches.length && (context = context.customShader || this._adaptor.shader, this.state.blendMode = graphics.groupBlendMode, context = context.resources.localUniforms.uniforms, context.uTransformMatrix = graphics.groupTransform, context.uRound = renderer._roundPixels | graphics._roundPixels, colorToUniform.color32BitToUniform(graphics.groupColorAlpha, context.uColor, 0), this._adaptor.execute(this, graphics));
|
|
}
|
|
}
|
|
_rebuild(graphics) {
|
|
const gpuData = this._getGpuDataForRenderable(graphics), gpuContext = this.renderer.graphicsContext.updateGpuContext(graphics.context);
|
|
gpuData.destroy();
|
|
gpuContext.isBatchable && this._updateBatchesForRenderable(graphics, gpuData);
|
|
}
|
|
_addToBatcher(graphics, instructionSet) {
|
|
const batchPipe = this.renderer.renderPipes.batch;
|
|
graphics = this._getGpuDataForRenderable(graphics).batches;
|
|
for (let i = 0; i < graphics.length; i++) {
|
|
batchPipe.addToBatch(graphics[i], instructionSet);
|
|
}
|
|
}
|
|
_getGpuDataForRenderable(graphics) {
|
|
return graphics._gpuData[this.renderer.uid] || this._initGpuDataForRenderable(graphics);
|
|
}
|
|
_initGpuDataForRenderable(graphics) {
|
|
const gpuData = new GraphicsGpuData();
|
|
graphics._gpuData[this.renderer.uid] = gpuData;
|
|
this._managedGraphics.add(graphics);
|
|
return gpuData;
|
|
}
|
|
_updateBatchesForRenderable(graphics, gpuData) {
|
|
const gpuContext = this.renderer.graphicsContext.getGpuContext(graphics.context), roundPixels = this.renderer._roundPixels | graphics._roundPixels;
|
|
gpuData.batches = gpuContext.batches.map(batch => {
|
|
const batchClone = PoolGroup.BigPool.get(BatchableGraphics.BatchableGraphics);
|
|
batch.copyTo(batchClone);
|
|
batchClone.renderable = graphics;
|
|
batchClone.roundPixels = roundPixels;
|
|
return batchClone;
|
|
});
|
|
}
|
|
destroy() {
|
|
this._managedGraphics.destroy();
|
|
this.renderer = null;
|
|
this._adaptor.destroy();
|
|
this.state = this._adaptor = null;
|
|
}
|
|
}
|
|
GraphicsPipe.extension = {type:[global.ExtensionType.WebGLPipes, global.ExtensionType.WebGPUPipes], name:"graphics"};
|
|
exports.GraphicsGpuData = GraphicsGpuData;
|
|
exports.GraphicsPipe = GraphicsPipe;
|
|
};
|
|
|
|
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$GraphicsPipe.js.map
|