Project

General

Profile

« Previous | Next » 

Revision 43814a57

Added by Leszek Koltunski almost 4 years ago

Fix the fact that the static DistortedEffects.mAllQueues was global, shared between all Activities.
Completely replace this mechanism with a non-static list of links from a VertexEffect to all VertexEffectQueues this effect is a member of.

View differences:

src/main/java/org/distorted/library/effect/Effect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.effectqueue.EffectQueue;
22 23
import org.distorted.library.message.EffectListener;
23 24

  
24 25
import java.lang.reflect.Method;
......
58 59
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
59 60
    }
60 61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  public abstract void addQueue(EffectQueue queue);
65
  public abstract void remQueue(EffectQueue queue);
66

  
61 67
///////////////////////////////////////////////////////////////////////////////////////////////////
62 68

  
63 69
  Effect(EffectName name)
src/main/java/org/distorted/library/effect/FragmentEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.effectqueue.EffectQueue;
22 23
import org.distorted.library.type.Static3D;
23 24

  
24 25
///////////////////////////////////////////////////////////////////////////////////////////////////
......
98 99
    mGLSL = "";
99 100
    }
100 101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
/**
104
 * Only for use by the library itself.
105
 *
106
 * @y.exclude
107
 */
108
  public void addQueue(EffectQueue queue)
109
    {
110
    // NO OP
111
    }
112

  
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
/**
115
 * Only for use by the library itself.
116
 *
117
 * @y.exclude
118
 */
119
  public void remQueue(EffectQueue queue)
120
    {
121
    // NO OP
122
    }
123

  
101 124
///////////////////////////////////////////////////////////////////////////////////////////////////
102 125
// PUBLIC API
103 126
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/effect/MatrixEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.effectqueue.EffectQueue;
23

  
22 24
///////////////////////////////////////////////////////////////////////////////////////////////////
23 25
/**
24 26
 * Abstract class that represents an Effect that works by modifying the ModelView matrix.
......
44 46
 */
45 47
  public abstract void apply(float[] matrixP, float[] matrixV, float[] uniforms, int index);
46 48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
/**
51
 * Only for use by the library itself.
52
 *
53
 * @y.exclude
54
 */
55
  public void addQueue(EffectQueue queue)
56
    {
57
    // NO OP
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * Only for use by the library itself.
63
 *
64
 * @y.exclude
65
 */
66
  public void remQueue(EffectQueue queue)
67
    {
68
    // NO OP
69
    }
70

  
47 71
///////////////////////////////////////////////////////////////////////////////////////////////////
48 72
// empty function for completeness
49 73

  
src/main/java/org/distorted/library/effect/PostprocessEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.effectqueue.EffectQueue;
22 23
import org.distorted.library.main.DistortedFramebuffer;
23 24
import org.distorted.library.main.InternalMaster;
24 25
import org.distorted.library.program.DistortedProgram;
......
165 166
    return mQualityLevel;
166 167
    }
167 168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170
/**
171
 * Only for use by the library itself.
172
 *
173
 * @y.exclude
174
 */
175
  public void addQueue(EffectQueue queue)
176
    {
177
    // NO OP
178
    }
179

  
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
/**
182
 * Only for use by the library itself.
183
 *
184
 * @y.exclude
185
 */
186
  public void remQueue(EffectQueue queue)
187
    {
188
    // NO OP
189
    }
190

  
168 191
///////////////////////////////////////////////////////////////////////////////////////////////////
169 192
/**
170 193
 * This is not really part of the public API. Has to be public only because it is a part of the
src/main/java/org/distorted/library/effect/VertexEffect.java
19 19

  
20 20
package org.distorted.library.effect;
21 21

  
22
import org.distorted.library.main.DistortedEffects;
22
import org.distorted.library.effectqueue.EffectQueue;
23 23
import org.distorted.library.type.Static4D;
24 24

  
25 25
import java.lang.reflect.Method;
26
import java.util.ArrayList;
26 27

  
27 28
///////////////////////////////////////////////////////////////////////////////////////////////////
28 29
/**
......
51 52

  
52 53
  final static Static4D MAX_REGION = new Static4D(0,0,0,1000000);
53 54

  
55
  ArrayList<EffectQueue> mQueues;
56

  
54 57
///////////////////////////////////////////////////////////////////////////////////////////////////
55 58

  
56 59
  VertexEffect(EffectName name)
......
194 197
    return mNumEnabled;
195 198
    }
196 199

  
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
/**
202
 * Only for use by the library itself.
203
 *
204
 * @y.exclude
205
 */
206
  public void addQueue(EffectQueue queue)
207
    {
208
    if( mQueues==null ) mQueues = new ArrayList<>();
209

  
210
    mQueues.add(queue);
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
/**
215
 * Only for use by the library itself.
216
 *
217
 * @y.exclude
218
 */
219
  public void remQueue(EffectQueue queue)
220
    {
221
    if( mQueues==null ) mQueues = new ArrayList<>();
222

  
223
    mQueues.remove(queue);
224
    }
225

  
197 226
///////////////////////////////////////////////////////////////////////////////////////////////////
198 227
/**
199 228
 * Set Mesh association.
......
214 243
    mAndAssociation = andAssociation;
215 244
    mEquAssociation = equAssociation;
216 245

  
217
    DistortedEffects.setAssociation(getID());
246
    long id = getID();
247
    int numQueues = mQueues==null ? 0: mQueues.size();
248

  
249
    for(int i=0; i<numQueues; i++)
250
      {
251
      EffectQueue queue = mQueues.get(i);
252
      queue.setAssociation(id);
253
      }
218 254
    }
219 255
  }
src/main/java/org/distorted/library/effectqueue/EffectQueue.java
260 260
    if( mNumEffects>pos )
261 261
      {
262 262
      mNumEffects--;
263
      mEffects[pos].remQueue(this);
263 264
      System.arraycopy(mEffects, pos+1, mEffects, pos, mNumEffects-pos);
264 265
      System.arraycopy(mIntUniforms, mNumIntUniforms*(pos+1), mIntUniforms, mNumIntUniforms*pos, mNumIntUniforms*(mNumEffects-pos) );
265 266
      mEffects[mNumEffects] = null;
......
273 274
    mEffects[pos]                     = effect;
274 275
    mIntUniforms[mNumIntUniforms*pos] = effect.getName().ordinal();
275 276

  
277
    effect.addQueue(this);
278

  
276 279
    if( mIndex==EffectType.VERTEX.ordinal() )
277 280
      {
278 281
      effect.writeAssociations(mIntUniforms, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3);
......
410 413
      }
411 414
    }
412 415

  
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

  
418
  public void setAssociation(long effectID)
419
    {
420
    for(int j=0; j<mNumEffects; j++)
421
      {
422
      if (mEffects[j].getID() == effectID)
423
        {
424
        mEffects[j].writeAssociations(mIntUniforms, mNumIntUniforms*j+1, mNumIntUniforms*j+3);
425
        }
426
      }
427
    }
428

  
413 429
///////////////////////////////////////////////////////////////////////////////////////////////////
414 430

  
415 431
  public void doWork()
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java
67 67
    mUniformsH[variant]  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
68 68
    }
69 69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
/**
72
 * Not part of public API, do not document (public only because has to be called from DistortedEffects)
73
 *
74
 * @y.exclude
75
 */
76
  public void setAssociation(long effectID)
77
    {
78
    for(int j=0; j<mNumEffects; j++)
79
      {
80
      if (mEffects[j].getID() == effectID)
81
        {
82
        mEffects[j].writeAssociations(mIntUniforms, NUM_INT_UNIFORMS*j+1, NUM_INT_UNIFORMS*j+3);
83
        }
84
      }
85
    }
86

  
87 70
///////////////////////////////////////////////////////////////////////////////////////////////////
88 71
/**
89 72
 * Not part of public API, do not document (public only because has to be used in Meshes)
src/main/java/org/distorted/library/main/DistortedEffects.java
23 23
import org.distorted.library.effect.EffectName;
24 24
import org.distorted.library.effectqueue.EffectQueue;
25 25
import org.distorted.library.effect.EffectType;
26
import org.distorted.library.effectqueue.EffectQueueVertex;
27

  
28
import java.util.ArrayList;
29 26

  
30 27
///////////////////////////////////////////////////////////////////////////////////////////////////
31 28
/**
......
35 32
 */
36 33
public class DistortedEffects
37 34
  {
38
  private static ArrayList<DistortedEffects> mAllEffectQueues = new ArrayList<>();
39 35
  private static long mNextID =0;
40 36
  private long mID;
41 37
  private EffectQueue[] mQueues;
......
54 50
  static void onDestroy()
55 51
    {
56 52
    mNextID =  0;
57
    mAllEffectQueues.clear();
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * @y.exclude
63
 */
64
  public static void setAssociation(long effectID)
65
    {
66
    EffectQueue[] queues;
67
    int numQueues = mAllEffectQueues.size();
68

  
69
    for(int i=0; i<numQueues; i++)
70
      {
71
      queues = mAllEffectQueues.get(i).getQueues();
72
      ((EffectQueueVertex)queues[1]).setAssociation(effectID);
73
      }
74 53
    }
75 54

  
76 55
///////////////////////////////////////////////////////////////////////////////////////////////////
......
84 63
    mID = ++mNextID;
85 64
    mQueues = new EffectQueue[EffectType.LENGTH];
86 65
    EffectQueue.allocateQueues(mQueues,null,0);
87
    mAllEffectQueues.add(this);
88 66
    }
89 67

  
90 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
102 80
    mID = ++mNextID;
103 81
    mQueues = new EffectQueue[EffectType.LENGTH];
104 82
    EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
105
    mAllEffectQueues.add(this);
106 83
    }
107 84

  
108 85
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/main/InternalBuffer.java
38 38
 */
39 39
public class InternalBuffer extends InternalObject
40 40
  {
41
  private static final int DONE     = 0;
41 42
  private static final int RECREATE = 1;
42 43
  private static final int UPDATE   = 2;
43 44

  
......
57 58
    mUsage  = usage;
58 59
    mBuffer = null;
59 60
    mSize   = 0;
60

  
61
    recreate();
61
    mStatus = RECREATE;
62 62
    }
63 63

  
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 93
      updateFloat(buffer);
94 94
      }
95 95

  
96
    mStatus = 0;
96
    mStatus = DONE;
97 97

  
98 98
    return mIndex[0];
99 99
    }
......
130 130
      updateInt(buffer);
131 131
      }
132 132

  
133
    mStatus = 0;
133
    mStatus = DONE;
134 134

  
135 135
    return mIndex[0];
136 136
    }
......
145 145
    GLES30.glBindBuffer( mTarget, mIndex[0]);
146 146
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
147 147
    GLES30.glBindBuffer( mTarget, 0);
148

  
149
    mStatus &= (~UPDATE);
148 150
    }
149 151

  
150 152
///////////////////////////////////////////////////////////////////////////////////////////////////
......
157 159
    GLES30.glBindBuffer( mTarget, mIndex[0]);
158 160
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
159 161
    GLES30.glBindBuffer( mTarget, 0);
162

  
163
    mStatus &= (~UPDATE);
160 164
    }
161 165

  
162 166
///////////////////////////////////////////////////////////////////////////////////////////////////
......
175 179
    GLES30.glBindBuffer( mTarget, mIndex[0]);
176 180
    GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage);
177 181
    GLES30.glBindBuffer( mTarget, 0);
182

  
183
    mStatus = DONE;
178 184
    }
179 185

  
180 186
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff