|
1 | 1 | /**
|
| 2 | + * The states that describe the lifecycle of a <code>Primitive</code>, as |
| 3 | + * represented by the <code>primitive._state</code>. |
| 4 | + * |
| 5 | + * The state transitions are triggered by calls to the <code>update</code> |
| 6 | + * function, but the actual state changes may happen asynchronously if the |
| 7 | + * <code>asynchronous</code> flag of the primitive was set to |
| 8 | + * <code>true</code>. |
| 9 | + * |
2 | 10 | * @private
|
3 | 11 | */
|
4 | 12 | const PrimitiveState = {
|
| 13 | + /** |
| 14 | + * The initial state of a primitive. |
| 15 | + * |
| 16 | + * Note that this does NOT mean that the primitive is "ready", as indicated |
| 17 | + * by the <code>_ready</code> property. It means the opposite: Nothing was |
| 18 | + * done with the primitive at all. |
| 19 | + * |
| 20 | + * For primitives that are created with the <code>asynchronous:true</code> |
| 21 | + * setting and that are in this state, the <code>update</code> call starts |
| 22 | + * the creation of the geometry using web workers, and the primitive goes |
| 23 | + * into the <code>CREATING</code> state. |
| 24 | + * |
| 25 | + * For synchronously created primitives, this state never matters. They will |
| 26 | + * go into the COMBINED (or FAILED) state directly due to a call to the |
| 27 | + * <code>update</code> function, if they are not yet FAILED, COMBINED, |
| 28 | + * or COMPLETE. |
| 29 | + */ |
5 | 30 | READY: 0,
|
| 31 | + |
| 32 | + /** |
| 33 | + * The process of creating the primitive geometry is ongoing. |
| 34 | + * |
| 35 | + * A primitive can only ever be in this state when it was created |
| 36 | + * with the <code>asynchronous:true</code> setting. |
| 37 | + * |
| 38 | + * It means that web workers are currently creating the geometry |
| 39 | + * of the primitive. |
| 40 | + * |
| 41 | + * When the geometry creation succeeds, then the primitive will go |
| 42 | + * into the CREATED state. Otherwise, it will go into the FAILED |
| 43 | + * state. Both will happen asynchronously. |
| 44 | + * |
| 45 | + * The <code>update</code> function has to be called regularly |
| 46 | + * until either of these states is reached. |
| 47 | + */ |
6 | 48 | CREATING: 1,
|
| 49 | + |
| 50 | + /** |
| 51 | + * The geometry for the primitive has been created. |
| 52 | + * |
| 53 | + * A primitive can only ever be in this state when it was created |
| 54 | + * with the <code>asynchronous:true</code> setting. |
| 55 | + * |
| 56 | + * It means that web workers have (asynchronously) finished the |
| 57 | + * creation of the geometry, but further (asynchronous) processing |
| 58 | + * is necessary: If a primitive is determined to be in this state |
| 59 | + * during a call to <code>update</code>, an asynchronous process |
| 60 | + * is triggered to "combine" the geometry, meaning that the primitive |
| 61 | + * will go into the COMBINING state. |
| 62 | + */ |
7 | 63 | CREATED: 2,
|
| 64 | + |
| 65 | + /** |
| 66 | + * The asynchronous creation of the geometry has been finished, but the |
| 67 | + * asynchronous process of combining the geometry has not finished yet. |
| 68 | + * |
| 69 | + * A primitive can only ever be in this state when it was created |
| 70 | + * with the <code>asynchronous:true</code> setting. |
| 71 | + * |
| 72 | + * It means that whatever is done with |
| 73 | + * <code>PrimitivePipeline.packCombineGeometryParameters</code> has |
| 74 | + * not finished yet. When combining the geometry succeeds, the |
| 75 | + * primitive will go into the COMBINED state. Otherwise, it will |
| 76 | + * go into the FAILED state. |
| 77 | + */ |
8 | 78 | COMBINING: 3,
|
| 79 | + |
| 80 | + /** |
| 81 | + * The geometry data is in a form that can be uploaded to the GPU. |
| 82 | + * |
| 83 | + * For <i>synchronous</i> primitives, this means that the geometry |
| 84 | + * has been created (synchronously) due to the first call to the |
| 85 | + * <code>update</code> function. |
| 86 | + * |
| 87 | + * For <i>asynchronous</i> primitives, this means that the asynchronous |
| 88 | + * creation of the geometry and the asynchronous combination of the |
| 89 | + * geometry have both finished. |
| 90 | + * |
| 91 | + * The <code>update</code> function has to be called regularly until |
| 92 | + * this state is reached. When it is reached, the <code>update</code> |
| 93 | + * call will cause the transition into the COMPLETE state. |
| 94 | + */ |
9 | 95 | COMBINED: 4,
|
| 96 | + |
| 97 | + /** |
| 98 | + * The geometry has been created and uploaded to the GPU. |
| 99 | + * |
| 100 | + * When this state is reached, it eventually causes the <code>_ready</code> |
| 101 | + * flag of the primitive to become <code>true</code>. |
| 102 | + * |
| 103 | + * Note: Setting the <code>ready</code> flag does NOT happen in the |
| 104 | + * <code>update</code> call: It only happens after rendering the next |
| 105 | + * frame! |
| 106 | + * |
| 107 | + * Note: This state does not mean that nothing has to be done |
| 108 | + * anymore (so the work is not "complete"). When the primitive is in |
| 109 | + * this state, the <code>update</code> function still has to be |
| 110 | + * called regularly. |
| 111 | + */ |
10 | 112 | COMPLETE: 5,
|
| 113 | + |
| 114 | + /** |
| 115 | + * The creation of the primitive failed. |
| 116 | + * |
| 117 | + * When this state is reached, it eventually causes the <code>_ready</code> |
| 118 | + * flag of the primitive to become <code>true</code>. |
| 119 | + * |
| 120 | + * Note: Setting the <code>ready</code> flag does NOT happen in the |
| 121 | + * <code>update</code> call: It only happens after rendering the next |
| 122 | + * frame! |
| 123 | + * |
| 124 | + * This state can be reached when the (synchronous or asynchronous) |
| 125 | + * creation of the geometry, or the (asynchronous) combination of |
| 126 | + * the geometry caused any form of error. |
| 127 | + * |
| 128 | + * It may or may not imply the presence of the <code>_error</code> property. |
| 129 | + * When the <code>_error</code> property is present on a FAILED primitive, |
| 130 | + * this error will be thrown during the <code>update</code> call. When it |
| 131 | + * is not present for a FAILED primitive, then the <code>update</code> call |
| 132 | + * will do nothing. |
| 133 | + */ |
11 | 134 | FAILED: 6,
|
12 | 135 | };
|
13 | 136 | export default Object.freeze(PrimitiveState);
|
0 commit comments