UNPKG

2.15 kBJavaScriptView Raw
1import { BLEND_MODES } from '@pixi/constants';
2
3const BLEND = 0;
4const OFFSET = 1;
5const CULLING = 2;
6const DEPTH_TEST = 3;
7const WINDING = 4;
8const DEPTH_MASK = 5;
9class State {
10 constructor() {
11 this.data = 0;
12 this.blendMode = BLEND_MODES.NORMAL;
13 this.polygonOffset = 0;
14 this.blend = true;
15 this.depthMask = true;
16 }
17 get blend() {
18 return !!(this.data & 1 << BLEND);
19 }
20 set blend(value) {
21 if (!!(this.data & 1 << BLEND) !== value) {
22 this.data ^= 1 << BLEND;
23 }
24 }
25 get offsets() {
26 return !!(this.data & 1 << OFFSET);
27 }
28 set offsets(value) {
29 if (!!(this.data & 1 << OFFSET) !== value) {
30 this.data ^= 1 << OFFSET;
31 }
32 }
33 get culling() {
34 return !!(this.data & 1 << CULLING);
35 }
36 set culling(value) {
37 if (!!(this.data & 1 << CULLING) !== value) {
38 this.data ^= 1 << CULLING;
39 }
40 }
41 get depthTest() {
42 return !!(this.data & 1 << DEPTH_TEST);
43 }
44 set depthTest(value) {
45 if (!!(this.data & 1 << DEPTH_TEST) !== value) {
46 this.data ^= 1 << DEPTH_TEST;
47 }
48 }
49 get depthMask() {
50 return !!(this.data & 1 << DEPTH_MASK);
51 }
52 set depthMask(value) {
53 if (!!(this.data & 1 << DEPTH_MASK) !== value) {
54 this.data ^= 1 << DEPTH_MASK;
55 }
56 }
57 get clockwiseFrontFace() {
58 return !!(this.data & 1 << WINDING);
59 }
60 set clockwiseFrontFace(value) {
61 if (!!(this.data & 1 << WINDING) !== value) {
62 this.data ^= 1 << WINDING;
63 }
64 }
65 get blendMode() {
66 return this._blendMode;
67 }
68 set blendMode(value) {
69 this.blend = value !== BLEND_MODES.NONE;
70 this._blendMode = value;
71 }
72 get polygonOffset() {
73 return this._polygonOffset;
74 }
75 set polygonOffset(value) {
76 this.offsets = !!value;
77 this._polygonOffset = value;
78 }
79 toString() {
80 return `[@pixi/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`;
81 }
82 static for2d() {
83 const state = new State();
84 state.depthTest = false;
85 state.blend = true;
86 return state;
87 }
88}
89
90export { State };
91//# sourceMappingURL=State.mjs.map