- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
import { BLEND_MODES } from '@pixi/constants';
/* eslint-disable max-len */
const BLEND = 0;
const OFFSET = 1;
const CULLING = 2;
const DEPTH_TEST = 3;
const WINDING = 4;
const DEPTH_MASK = 5;
/**
* This is a WebGL state, and is is passed to {@link PIXI.StateSystem}.
*
* Each mesh rendered may require WebGL to be in a different state.
* For example you may want different blend mode or to enable polygon offsets
* @memberof PIXI
*/
export class State
{
data: number;
_blendMode: BLEND_MODES;
_polygonOffset: number;
constructor()
{
this.data = 0;
this.blendMode = BLEND_MODES.NORMAL;
this.polygonOffset = 0;
this.blend = true;
this.depthMask = true;
// this.depthTest = true;
}
/**
* Activates blending of the computed fragment color values.
* @default true
*/
get blend(): boolean
{
return !!(this.data & (1 << BLEND));
}
set blend(value: boolean)
{
if (!!(this.data & (1 << BLEND)) !== value)
{
this.data ^= (1 << BLEND);
}
}
/**
* Activates adding an offset to depth values of polygon's fragments
* @default false
*/
get offsets(): boolean
{
return !!(this.data & (1 << OFFSET));
}
set offsets(value: boolean)
{
if (!!(this.data & (1 << OFFSET)) !== value)
{
this.data ^= (1 << OFFSET);
}
}
/**
* Activates culling of polygons.
* @default false
*/
get culling(): boolean
{
return !!(this.data & (1 << CULLING));
}
set culling(value: boolean)
{
if (!!(this.data & (1 << CULLING)) !== value)
{
this.data ^= (1 << CULLING);
}
}
/**
* Activates depth comparisons and updates to the depth buffer.
* @default false
*/
get depthTest(): boolean
{
return !!(this.data & (1 << DEPTH_TEST));
}
set depthTest(value: boolean)
{
if (!!(this.data & (1 << DEPTH_TEST)) !== value)
{
this.data ^= (1 << DEPTH_TEST);
}
}
/**
* Enables or disables writing to the depth buffer.
* @default true
*/
get depthMask(): boolean
{
return !!(this.data & (1 << DEPTH_MASK));
}
set depthMask(value: boolean)
{
if (!!(this.data & (1 << DEPTH_MASK)) !== value)
{
this.data ^= (1 << DEPTH_MASK);
}
}
/**
* Specifies whether or not front or back-facing polygons can be culled.
* @default false
*/
get clockwiseFrontFace(): boolean
{
return !!(this.data & (1 << WINDING));
}
set clockwiseFrontFace(value: boolean)
{
if (!!(this.data & (1 << WINDING)) !== value)
{
this.data ^= (1 << WINDING);
}
}
/**
* The blend mode to be applied when this state is set. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
* Setting this mode to anything other than NO_BLEND will automatically switch blending on.
* @default PIXI.BLEND_MODES.NORMAL
*/
get blendMode(): BLEND_MODES
{
return this._blendMode;
}
set blendMode(value: BLEND_MODES)
{
this.blend = (value !== BLEND_MODES.NONE);
this._blendMode = value;
}
/**
* The polygon offset. Setting this property to anything other than 0 will automatically enable polygon offset fill.
* @default 0
*/
get polygonOffset(): number
{
return this._polygonOffset;
}
set polygonOffset(value: number)
{
this.offsets = !!value;
this._polygonOffset = value;
}
// #if _DEBUG
toString(): string
{
return `[@pixi/core:State `
+ `blendMode=${this.blendMode} `
+ `clockwiseFrontFace=${this.clockwiseFrontFace} `
+ `culling=${this.culling} `
+ `depthMask=${this.depthMask} `
+ `polygonOffset=${this.polygonOffset}`
+ `]`;
}
// #endif
static for2d(): State
{
const state = new State();
state.depthTest = false;
state.blend = true;
return state;
}
}