phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
76 lines (64 loc) • 2.43 kB
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2025 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../../utils/Class');
var GetFastValue = require('../../../utils/object/GetFastValue');
var MultiPipeline = require('./MultiPipeline');
var ShaderSourceFS = require('../shaders/Single-frag');
var ShaderSourceVS = require('../shaders/Single-vert');
var WebGLPipeline = require('../WebGLPipeline');
/**
* @classdesc
* The Single Pipeline is a special version of the Multi Pipeline that only ever
* uses one texture, bound to texture unit zero. Although not as efficient as the
* Multi Pipeline, it provides an easier way to create custom pipelines that only require
* a single bound texture.
*
* Prior to Phaser v3.50 this pipeline didn't exist, but could be compared to the old `TextureTintPipeline`.
*
* The fragment shader it uses can be found in `shaders/src/Single.frag`.
* The vertex shader it uses can be found in `shaders/src/Single.vert`.
*
* The default shader attributes for this pipeline are:
*
* `inPosition` (vec2, offset 0)
* `inTexCoord` (vec2, offset 8)
* `inTexId` (float, offset 16) - this value is always zero in the Single Pipeline
* `inTintEffect` (float, offset 20)
* `inTint` (vec4, offset 24, normalized)
*
* The default shader uniforms for this pipeline are:
*
* `uProjectionMatrix` (mat4)
* `uResolution` (vec2)
* `uMainSampler` (sampler2D, or sampler2D array)
*
* @class SinglePipeline
* @extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline
* @memberof Phaser.Renderer.WebGL.Pipelines
* @constructor
* @since 3.50.0
*
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig} config - The configuration options for this pipeline.
*/
var SinglePipeline = new Class({
Extends: MultiPipeline,
initialize:
function SinglePipeline (config)
{
config.fragShader = GetFastValue(config, 'fragShader', ShaderSourceFS),
config.vertShader = GetFastValue(config, 'vertShader', ShaderSourceVS),
config.forceZero = true;
MultiPipeline.call(this, config);
},
boot: function ()
{
WebGLPipeline.prototype.boot.call(this);
var renderer = this.renderer;
this.set1i('uMainSampler', 0);
this.set2f('uResolution', renderer.width, renderer.height);
}
});
module.exports = SinglePipeline;