Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 65535 is max vertex index in the index buffer (see ParticleRenderer)
// so max number of particles is 65536 / 4 = 16384
// and max number of element in the index buffer is 16384 * 6 = 98304
// Creating a full index buffer, overhead is 98304 * 2 = 196Ko
// let numIndices = 98304;
/**
* The default shader that is used if a sprite doesn't have a more specific one.
*
* @member {PIXI.Shader}
*/
this.shader = null;
this.properties = null;
this.tempMatrix = new Matrix();
this.properties = [
// verticesData
{
attributeName: 'aVertexPosition',
size: 2,
uploadFunction: this.uploadVertices,
offset: 0,
},
// positionData
{
attributeName: 'aPositionCoord',
size: 2,
uploadFunction: this.uploadPosition,
offset: 0,
},
if (!this.shader)
{
// if there is no shader here, we can use the default shader.
// and that only gets created if we actually need it..
if (!defaultShader)
{
const sampleValues = new Int32Array(16);
for (let i = 0; i < 16; i++)
{
sampleValues[i] = i;
}
const uniforms = {
tint: new Float32Array([1, 1, 1, 1]),
translationMatrix: new Matrix(),
default: UniformGroup.from({ uSamplers: sampleValues }, true),
};
// we can bbase default shader of the batch renderers program
const program = renderer.plugins.batch._shader.program;
defaultShader = new Shader(program, uniforms);
}
this.shader = defaultShader;
}
const uniforms = this.shader.uniforms;
// lets set the transfomr
uniforms.translationMatrix = this.transform.worldTransform;
import { Texture, BaseTexture, RenderTexture } from '@pixi/core';
import { Sprite } from '@pixi/sprite';
import { DisplayObject } from '@pixi/display';
import { Matrix } from '@pixi/math';
import { uid } from '@pixi/utils';
import { settings } from '@pixi/settings';
const _tempMatrix = new Matrix();
DisplayObject.prototype._cacheAsBitmap = false;
DisplayObject.prototype._cacheData = false;
// figured theres no point adding ALL the extra variables to prototype.
// this model can hold the information needed. This can also be generated on demand as
// most objects are not cached as bitmaps.
/**
* @class
* @ignore
*/
class CacheData
{
constructor()
{
this.textureCacheId = null;
constructor()
{
/**
* The global matrix transform. It can be swapped temporarily by some functions like getLocalBounds()
*
* @member {PIXI.Matrix}
*/
this.worldTransform = new Matrix();
/**
* The local matrix transform
*
* @member {PIXI.Matrix}
*/
this.localTransform = new Matrix();
this._worldID = 0;
this._parentID = 0;
}
constructor()
{
/**
* The global matrix transform. It can be swapped temporarily by some functions like getLocalBounds()
*
* @member {PIXI.Matrix}
*/
this.worldTransform = new Matrix();
/**
* The local matrix transform
*
* @member {PIXI.Matrix}
*/
this.localTransform = new Matrix();
this._worldID = 0;
this._parentID = 0;
}
this.runners = {
destroy: new Runner('destroy'),
contextChange: new Runner('contextChange', 1),
reset: new Runner('reset'),
update: new Runner('update'),
postrender: new Runner('postrender'),
prerender: new Runner('prerender'),
resize: new Runner('resize', 2),
};
/**
* Global uniforms
* @member {PIXI.UniformGroup}
*/
this.globalUniforms = new UniformGroup({
projectionMatrix: new Matrix(),
}, true);
/**
* Mask system instance
* @member {PIXI.systems.MaskSystem} mask
* @memberof PIXI.Renderer#
* @readonly
*/
this.addSystem(MaskSystem, 'mask')
/**
* Context system instance
* @member {PIXI.systems.ContextSystem} context
* @memberof PIXI.Renderer#
* @readonly
*/
.addSystem(ContextSystem, 'context')
import { SCALE_MODES, BLEND_MODES } from '@pixi/constants';
import { Matrix, GroupD8 } from '@pixi/math';
import { CanvasTinter } from '@pixi/canvas-renderer';
const canvasRenderWorldTransform = new Matrix();
/**
* Types that can be passed to drawImage
* @typedef {HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap} ICanvasImageSource
* @memberof PIXI
*/
/**
* @author Mat Groves
*
* Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/
* for creating the original PixiJS version!
* Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now
* share 4 bytes on the vertex buffer
*
* Heavily inspired by LibGDX's CanvasSpriteRenderer:
*/
this.sourceFrame = null;
/**
* Default destination frame
* @member {PIXI.Rectangle}
* @readonly
*/
this.defaultFrame = null;
/**
* Project matrix
* @member {PIXI.Matrix}
* @readonly
*/
this.projectionMatrix = new Matrix();
/**
* A transform that will be appended to the projection matrix
* if null, nothing will be applied
* @member {PIXI.Matrix}
*/
this.transform = null;
}
import { ObjectRenderer, Shader, State, QuadUv } from '@pixi/core';
import { WRAP_MODES } from '@pixi/constants';
import { Matrix } from '@pixi/math';
import { premultiplyTintToRgba, correctBlendMode } from '@pixi/utils';
import vertex from './tilingSprite.vert';
import fragment from './tilingSprite.frag';
import fragmentSimple from './tilingSprite_simple.frag';
const tempMat = new Matrix();
/**
* WebGL renderer plugin for tiling sprites
*
* @class
* @memberof PIXI
* @extends PIXI.ObjectRenderer
*/
export class TilingSpriteRenderer extends ObjectRenderer
{
/**
* constructor for renderer
*
* @param {PIXI.Renderer} renderer The renderer this tiling awesomeness works for.
*/
constructor(renderer)
sampleValues[i] = i;
}
this.defaultGroupCache[maxTextures] = UniformGroup.from({ uSamplers: sampleValues }, true);
let fragmentSrc = this.fragTemplate;
fragmentSrc = fragmentSrc.replace(/%count%/gi, `${maxTextures}`);
fragmentSrc = fragmentSrc.replace(/%forloop%/gi, this.generateSampleSrc(maxTextures));
this.programCache[maxTextures] = new Program(this.vertexSrc, fragmentSrc);
}
const uniforms = {
tint: new Float32Array([1, 1, 1, 1]),
translationMatrix: new Matrix(),
default: this.defaultGroupCache[maxTextures],
};
return new Shader(this.programCache[maxTextures], uniforms);
}